https://gcc.gnu.org/g:831a427a5236022bd5f7b20aa73cce9f61cdc030

commit r17-1899-g831a427a5236022bd5f7b20aa73cce9f61cdc030
Author: Arthur Cohen <[email protected]>
Date:   Fri May 29 15:37:48 2026 +0200

    gccrs: nr: Remove hack around resolving modules
    
    Remove the previous hack that was used for resolver module names in the 
Types NS. Modules now
    get properly inserted, and this hack causes conflicts when a module and 
value share the same
    name.
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-name-resolution-context.hxx: Remove hacks.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-4563.rs: New test.

Diff:
---
 gcc/rust/resolve/rust-name-resolution-context.hxx | 43 -----------------------
 gcc/testsuite/rust/compile/issue-4563.rs          | 12 +++++++
 2 files changed, 12 insertions(+), 43 deletions(-)

diff --git a/gcc/rust/resolve/rust-name-resolution-context.hxx 
b/gcc/rust/resolve/rust-name-resolution-context.hxx
index 7a8f24ac5150..7de8da097fef 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.hxx
+++ b/gcc/rust/resolve/rust-name-resolution-context.hxx
@@ -180,28 +180,6 @@ NameResolutionContext::resolve_path (
              // TODO: does NonShadowable matter?
              return Rib::Definition::NonShadowable (id);
            }
-         else
-           {
-             // HACK: check for a module after we check the language prelude
-             for (auto &kv :
-                  stack.find_closest_module (starting_point.get ()).children)
-               {
-                 auto &link = kv.first;
-
-                 if (link.path.map_or (
-                       [&seg] (Identifier path) {
-                         auto &path_str = path.as_string ();
-                         return path_str == seg.name;
-                       },
-                       false))
-                   {
-                     // FIXME: Is the NS to insert_segment_resolution valid?
-                     insert_segment_resolution (Usage (seg.node_id),
-                                                Definition (kv.second.id), N);
-                     return Rib::Definition::NonShadowable (kv.second.id);
-                   }
-               }
-           }
        }
 
       // FIXME: Is the NS to insert_segment_resolution valid?
@@ -262,27 +240,6 @@ NameResolutionContext::resolve_path (
   if (!res)
     res = stack.get_lang_prelude (seg_name);
 
-  if (N == Namespace::Types && !res)
-    {
-      // HACK: check for a module after we check the language prelude
-      for (auto &kv : final_node.children)
-       {
-         auto &link = kv.first;
-
-         if (link.path.map_or (
-               [&seg_name] (Identifier path) {
-                 auto &path_str = path.as_string ();
-                 return path_str == seg_name;
-               },
-               false))
-           {
-             insert_segment_resolution (Usage (seg.node_id),
-                                        Definition (kv.second.id), N);
-             return Rib::Definition::NonShadowable (kv.second.id);
-           }
-       }
-    }
-
   if (res && !res->is_ambiguous ())
     insert_segment_resolution (Usage (seg.node_id),
                               Definition (res->get_node_id ()), N);
diff --git a/gcc/testsuite/rust/compile/issue-4563.rs 
b/gcc/testsuite/rust/compile/issue-4563.rs
new file mode 100644
index 000000000000..835fd773a952
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4563.rs
@@ -0,0 +1,12 @@
+#![feature(no_core)]
+#![no_core]
+
+mod foo {
+    pub fn foo() {}
+}
+
+use foo::foo;
+
+fn main() {
+    foo();
+}

Reply via email to