From: Pierre-Emmanuel Patry <[email protected]>

Return the injected crate's node id.

gcc/rust/ChangeLog:

        * ast/rust-ast.cc (Crate::inject_extern_crate): Return the injected
        crate's node id.
        * ast/rust-ast.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>

Tested on x86_64-pc-linux-gnu.

---
 gcc/rust/ast/rust-ast.cc | 9 ++++++---
 gcc/rust/ast/rust-ast.h  | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 091cdf5ac45..97f575d3075 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -235,12 +235,15 @@ Crate::as_string () const
   return str + "\n";
 }
 
-void
+NodeId
 Crate::inject_extern_crate (std::string name)
 {
-  items.push_back (std::make_unique<AST::ExternCrate> (
+  auto extern_crate = std::make_unique<AST::ExternCrate> (
     AST::ExternCrate (name, AST::Visibility::create_public (UNKNOWN_LOCATION),
-                     {}, UNKNOWN_LOCATION)));
+                     {}, UNKNOWN_LOCATION));
+  auto node_id = extern_crate->get_node_id ();
+  items.push_back (std::move (extern_crate));
+  return node_id;
 }
 
 void
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index bbba4a5c33c..50778bcaffe 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -2092,7 +2092,7 @@ public:
     // TODO: is this the best way to do this?
   }
 
-  void inject_extern_crate (std::string name);
+  NodeId inject_extern_crate (std::string name);
   void inject_inner_attribute (Attribute attribute);
 
   NodeId get_node_id () const { return node_id; }
-- 
2.55.0

Reply via email to