From: Arthur Cohen <[email protected]>

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.
---
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/c4ccf5935037345a0ec009fab1aac6b5acea9a2a

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/4404

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

diff --git a/gcc/rust/resolve/rust-name-resolution-context.hxx 
b/gcc/rust/resolve/rust-name-resolution-context.hxx
index 7a8f24ac5..7de8da097 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 000000000..835fd773a
--- /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();
+}
-- 
2.54.0

Reply via email to