From: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>

Definition/usage mapping during name resolution was missing.

gcc/rust/ChangeLog:

        * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add mapping
        implementation.
        * resolve/rust-late-name-resolver-2.0.h: Add function visitor prototype
        override.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>
---
 .../resolve/rust-late-name-resolver-2.0.cc    | 21 +++++++++++++++++++
 .../resolve/rust-late-name-resolver-2.0.h     |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index dc7cde1b323..f580c23377b 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -228,5 +228,26 @@ Late::visit (AST::TypePath &type)
                 Definition (resolved->get_node_id ()));
 }
 
+void
+Late::visit (AST::StructExprStructBase &s)
+{
+  auto resolved = ctx.types.get (s.get_struct_name ().as_string ());
+
+  ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
+                Definition (resolved->get_node_id ()));
+  DefaultResolver::visit (s);
+}
+
+void
+Late::visit (AST::StructExprStructFields &s)
+{
+  auto resolved = ctx.types.get (s.get_struct_name ().as_string ());
+
+  ctx.map_usage (Usage (s.get_struct_name ().get_node_id ()),
+                Definition (resolved->get_node_id ()));
+
+  DefaultResolver::visit (s);
+}
+
 } // namespace Resolver2_0
 } // namespace Rust
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 3a8a0060f5a..ee712b305d4 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -46,6 +46,8 @@ public:
   void visit (AST::IdentifierExpr &) override;
   void visit (AST::PathInExpression &) override;
   void visit (AST::TypePath &) override;
+  void visit (AST::StructExprStructBase &) override;
+  void visit (AST::StructExprStructFields &) override;
 
 private:
   /* Setup Rust's builtin types (u8, i32, !...) in the resolver */
-- 
2.45.2

Reply via email to