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

Macros imported from extern crates using the macro_use prelude should
be resolved and remain shadowable, and thus be resolved after all other
namespaces.

gcc/rust/ChangeLog:

        * resolve/rust-forever-stack.h: Add function prototype.
        * resolve/rust-forever-stack.hxx: Add function to retrieve identifier
        from macro_use prelude.
        * resolve/rust-name-resolution-context.hxx: Lookup macro_use prelude
        when everything else has failed.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
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/b3b1120c56db386152154e90ff82718f71eedd5e

The commit has NOT been mentioned in any issue.

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

 gcc/rust/resolve/rust-forever-stack.h             | 1 +
 gcc/rust/resolve/rust-forever-stack.hxx           | 8 ++++++++
 gcc/rust/resolve/rust-name-resolution-context.hxx | 2 ++
 3 files changed, 11 insertions(+)

diff --git a/gcc/rust/resolve/rust-forever-stack.h 
b/gcc/rust/resolve/rust-forever-stack.h
index 5d6a7e564..c846eca60 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -747,6 +747,7 @@ 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_macro_use_prelude (const Identifier &name);
   tl::optional<Rib::Definition> get_from_prelude (NodeId prelude,
                                                  const Identifier &name);
 
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index 28979f97f..c3e284e1a 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -381,6 +381,14 @@ ForeverStack<N>::get_lang_prelude (const std::string &name)
   return lang_prelude.rib (N).get (name);
 }
 
+template <Namespace N>
+tl::optional<Rib::Definition>
+ForeverStack<N>::get_macro_use_prelude (const Identifier &name)
+{
+  rust_assert (N == Namespace::Macros);
+  return macro_use_prelude.rib (N).get (name);
+}
+
 template <Namespace N>
 tl::optional<Rib::Definition>
 ForeverStack<N>::get_from_prelude (NodeId prelude, const Identifier &name)
diff --git a/gcc/rust/resolve/rust-name-resolution-context.hxx 
b/gcc/rust/resolve/rust-name-resolution-context.hxx
index 9741e5da1..00dabb669 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.hxx
+++ b/gcc/rust/resolve/rust-name-resolution-context.hxx
@@ -144,6 +144,8 @@ NameResolutionContext::resolve_path (
 
       if (!res)
        res = stack.get_lang_prelude (seg.name);
+      if (N == Namespace::Macros && !res)
+       res = stack.get_macro_use_prelude (seg.name);
 
       if (N == Namespace::Types && !res)
        {
-- 
2.56.1

Reply via email to