diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index 8f6e7faa0c4..a755d03831f 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -18,6 +18,7 @@ #include "rust-expand-visitor.h" #include "rust-ast-fragment.h" +#include "rust-hir-map.h" #include "rust-proc-macro.h" #include "rust-attributes.h" #include "rust-ast.h" @@ -47,7 +48,10 @@ static std::vector> builtin_derive_item (AST::Item &item, const AST::Attribute &derive, BuiltinMacro to_derive) { - return AST::DeriveVisitor::derive (item, derive, to_derive); + auto items = AST::DeriveVisitor::derive (item, derive, to_derive); + for (auto &item : items) + Analysis::Mappings::get ().add_derived_nodes (item->get_node_id ()); + return items; } static std::vector> @@ -63,6 +67,8 @@ derive_item (AST::Item &item, AST::SimplePath &to_derive, switch (node.get_kind ()) { case AST::SingleASTNode::ITEM: + Analysis::Mappings::get ().add_derived_nodes ( + node.get_item ()->get_node_id ()); result.push_back (node.take_item ()); break; default: diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 4629e6a5702..cf87219c9e2 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -1358,5 +1358,17 @@ Mappings::lookup_captures (NodeId closure) return cap->second; } +void +Mappings::add_derived_nodes (NodeId node_id) +{ + derived_nodes.insert (node_id); +} + +bool +Mappings::is_derived_node (NodeId node_id) +{ + return derived_nodes.find (node_id) != derived_nodes.end (); +} + } // namespace Analysis } // namespace Rust diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index c8fafa4a35f..97cd2f5c373 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -350,6 +350,9 @@ class Mappings void add_capture (NodeId closure, NodeId definition); tl::optional> lookup_captures (NodeId closure); + void add_derived_nodes (NodeId node_id); + bool is_derived_node (NodeId node_id); + private: Mappings (); @@ -443,6 +446,8 @@ class Mappings // Closure AST NodeId -> vector of Definition node ids std::unordered_map> captures; + + std::set derived_nodes; }; } // namespace Analysis