From: Philip Herron <[email protected]>

Fixes Rust-GCC/gccrs#4477

gcc/rust/ChangeLog:

        * expand/rust-expand-visitor.cc (builtin_derive_item): check for null 
and remove

Signed-off-by: Philip Herron <[email protected]>

Tested on x86_64-pc-linux-gnu.

---
 gcc/rust/expand/rust-expand-visitor.cc | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/expand/rust-expand-visitor.cc 
b/gcc/rust/expand/rust-expand-visitor.cc
index 3a042ac9a9c..e78f723053b 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -49,13 +49,22 @@ static std::vector<std::unique_ptr<AST::Item>>
 builtin_derive_item (AST::Item &item, const AST::Attribute &derive,
                     BuiltinMacro to_derive, MacroExpander &expander)
 {
+  auto &mappings = Analysis::Mappings::get ();
   auto item_source = AST::Builder::get_item_source (expander.crate);
 
   auto items
     = AST::DeriveVisitor::derive (item, derive, to_derive, item_source);
 
-  for (auto &item : items)
-    Analysis::Mappings::get ().add_derived_node (item->get_node_id ());
+  for (auto it = items.begin (); it != items.end ();)
+    {
+      if (*it == nullptr)
+       it = items.erase (it);
+      else
+       {
+         mappings.add_derived_node ((*it)->get_node_id ());
+         ++it;
+       }
+    }
 
   return items;
 }
-- 
2.55.0

Reply via email to