]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Use name resolver 2.0 in CompileTraitItem
authorOwen Avery <powerboat9.gamer@gmail.com>
Sat, 26 Oct 2024 23:53:42 +0000 (19:53 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 21 Mar 2025 11:32:54 +0000 (12:32 +0100)
gcc/rust/ChangeLog:

* backend/rust-compile-implitem.cc
(CompileTraitItem::visit): Use name resolver 2.0 (when enabled)
to obtain canonical paths for instances of TraitItemConst and
TraitItemFunc.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/backend/rust-compile-implitem.cc

index 4c7d8e821a195c44eab67cdf6fb09fe9a5fd4c88..98337c8f9bb451b521ae1004c86457be3dcd764a 100644 (file)
@@ -27,8 +27,22 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
   rust_assert (concrete != nullptr);
   TyTy::BaseType *resolved_type = concrete;
 
-  auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
-    constant.get_mappings ().get_nodeid ());
+  tl::optional<Resolver::CanonicalPath> canonical_path;
+  if (flag_name_resolution_2_0)
+    {
+      auto &nr_ctx
+       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+      canonical_path = nr_ctx.values.to_canonical_path (
+       constant.get_mappings ().get_nodeid ());
+    }
+  else
+    {
+      canonical_path = ctx->get_mappings ().lookup_canonical_path (
+       constant.get_mappings ().get_nodeid ());
+    }
+
+  rust_assert (canonical_path);
 
   HIR::Expr *const_value_expr = constant.get_expr ().get ();
   tree const_expr
@@ -75,8 +89,22 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
       fntype->override_context ();
     }
 
-  auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
-    func.get_mappings ().get_nodeid ());
+  tl::optional<Resolver::CanonicalPath> canonical_path;
+  if (flag_name_resolution_2_0)
+    {
+      auto &nr_ctx
+       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+      canonical_path
+       = nr_ctx.values.to_canonical_path (func.get_mappings ().get_nodeid ());
+    }
+  else
+    {
+      canonical_path = ctx->get_mappings ().lookup_canonical_path (
+       func.get_mappings ().get_nodeid ());
+    }
+
+  rust_assert (canonical_path);
 
   // FIXME: How do we get the proper visibility here?
   auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);