]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: nr2.0: Adjust resolution of modules
authorOwen Avery <powerboat9.gamer@gmail.com>
Thu, 29 May 2025 21:04:46 +0000 (17:04 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:52 +0000 (16:36 +0200)
This prioritizes resolution in the language prelude over resolution as a
module.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx (ForeverStack::resolve_path):
Resolve final segments which point to modules.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Avoid inserting module names into ribs in the type namespace.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove issue-3315-2.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/resolve/rust-forever-stack.hxx
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
gcc/testsuite/rust/compile/nr2/exclude

index 582e53b1602220b307aaccc7852a97be2c417a34..1ed87b3d55b4ed0b5547ad9173fc9bbf50eb736c 100644 (file)
@@ -687,7 +687,7 @@ ForeverStack<N>::resolve_path (
       if (!res)
        res = get_lang_prelude (seg.as_string ());
 
-      if (!res && N == Namespace::Types)
+      if (N == Namespace::Types && !res)
        {
          if (seg.is_crate_path_seg ())
            {
@@ -719,6 +719,26 @@ ForeverStack<N>::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 :
+                  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.as_string ();
+                       },
+                       false))
+                   {
+                     insert_segment_resolution (outer_seg, kv.second.id);
+                     return Rib::Definition::NonShadowable (kv.second.id);
+                   }
+               }
+           }
        }
 
       if (res && !res->is_ambiguous ())
@@ -751,6 +771,26 @@ ForeverStack<N>::resolve_path (
       if (!res)
        res = 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 (segments.back (), kv.second.id);
+                 return Rib::Definition::NonShadowable (kv.second.id);
+               }
+           }
+       }
+
       if (res && !res->is_ambiguous ())
        insert_segment_resolution (segments.back (), res->get_node_id ());
 
index 8ec31c0351ffefa0db68f270f4301beea00b7d67..a7b442d5b440666d9abe38d340b6fc13e4060b8a 100644 (file)
@@ -101,8 +101,6 @@ TopLevel::go (AST::Crate &crate)
 void
 TopLevel::visit (AST::Module &module)
 {
-  insert_or_error_out (module.get_name (), module, Namespace::Types);
-
   // Parse the module's items if they haven't been expanded and the file
   // should be parsed (i.e isn't hidden behind an untrue or impossible cfg
   // directive
index 43d7a0dc9116fbe8b4a5648782a0a469b135d416..b8eaa81dbf73c379acec48bd3b8e7dd7290190d9 100644 (file)
@@ -1,2 +1 @@
-issue-3315-2.rs
 # please don't delete the trailing newline