From: Arthur Cohen <[email protected]>

gcc/rust/ChangeLog:

        * resolve/rust-forever-stack.h: New function.
        * resolve/rust-forever-stack.hxx: Implement it.
        * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Call it if the 
prelude exists
        and we have an unresolved Identifier Call it if the prelude exists and 
we have
        an unresolved Identifier.
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/6b97bfc022831822494229fff7b65be9b5d82797

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4149

 gcc/rust/resolve/rust-forever-stack.h           |  2 ++
 gcc/rust/resolve/rust-forever-stack.hxx         | 11 +++++++++++
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 12 +++++++++++-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-forever-stack.h 
b/gcc/rust/resolve/rust-forever-stack.h
index 2a88df7b9..cca98b55c 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -668,6 +668,8 @@ public:
   tl::optional<Rib::Definition> get (const Identifier &name);
   tl::optional<Rib::Definition> get_lang_prelude (const Identifier &name);
   tl::optional<Rib::Definition> get_lang_prelude (const std::string &name);
+  tl::optional<Rib::Definition> get_from_prelude (NodeId prelude,
+                                                 const Identifier &name);
 
   /**
    * Resolve a path to its definition in the current `ForeverStack`
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index bd35d6c4e..1093646eb 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -343,6 +343,17 @@ ForeverStack<N>::get_lang_prelude (const std::string &name)
   return lang_prelude.rib.get (name);
 }
 
+template <Namespace N>
+tl::optional<Rib::Definition>
+ForeverStack<N>::get_from_prelude (NodeId prelude, const Identifier &name)
+{
+  auto starting_point = dfs_node (root, prelude);
+  if (!starting_point)
+    return tl::nullopt;
+
+  return get (*starting_point, name);
+}
+
 template <>
 tl::optional<Rib::Definition> inline ForeverStack<Namespace::Labels>::get (
   const Identifier &name)
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 0da8c38b6..9a7c2f8a0 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -346,7 +346,17 @@ Late::visit (AST::IdentifierExpr &expr)
        {
          resolved = type;
        }
-      else
+      else if (!resolved && ctx.prelude)
+       {
+         resolved
+           = ctx.values.get_from_prelude (*ctx.prelude, expr.get_ident ());
+
+         if (!resolved)
+           resolved
+             = ctx.types.get_from_prelude (*ctx.prelude, expr.get_ident ());
+       }
+
+      if (!resolved)
        {
          rust_error_at (expr.get_locus (), ErrorCode::E0425,
                         "cannot find value %qs in this scope",
-- 
2.52.0

Reply via email to