]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
nr2.0: Fix borrow checking
authorOwen Avery <powerboat9.gamer@gmail.com>
Fri, 9 May 2025 22:02:29 +0000 (18:02 -0400)
committerPhilip Herron <philip.herron@embecosm.com>
Tue, 13 May 2025 09:18:03 +0000 (09:18 +0000)
gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h: Include
"rust-immutable-name-resolution-context.h" and "options.h".
(AbstractBuilder::resolve_label): Use the 2.0 name resolver when
it's enabled.
(AbstractBuilder::resolve_variable): Likewise.
(AbstractBuilder::resolve_variable_or_fn): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h

index 8de6b8b00a9158a89080921e52aeb5a7b4ddbd28..f636bda7e6480e91994e4b250e12afe31fce9689 100644 (file)
@@ -27,6 +27,8 @@
 #include "rust-name-resolver.h"
 #include "rust-bir.h"
 #include "rust-bir-free-region.h"
+#include "rust-immutable-name-resolution-context.h"
+#include "options.h"
 
 namespace Rust {
 
@@ -402,19 +404,40 @@ protected: // HIR resolution helpers
   template <typename T> NodeId resolve_label (T &expr)
   {
     NodeId resolved_label;
-    bool ok
-      = ctx.resolver.lookup_resolved_label (expr.get_mappings ().get_nodeid (),
-                                           &resolved_label);
-    rust_assert (ok);
+    if (flag_name_resolution_2_0)
+      {
+       auto &nr_ctx
+         = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+       auto res = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
+       rust_assert (res.has_value ());
+       resolved_label = res.value ();
+      }
+    else
+      {
+       bool ok = ctx.resolver.lookup_resolved_label (
+         expr.get_mappings ().get_nodeid (), &resolved_label);
+       rust_assert (ok);
+      }
     return resolved_label;
   }
 
   template <typename T> PlaceId resolve_variable (T &variable)
   {
     NodeId variable_id;
-    bool ok = ctx.resolver.lookup_resolved_name (
-      variable.get_mappings ().get_nodeid (), &variable_id);
-    rust_assert (ok);
+    if (flag_name_resolution_2_0)
+      {
+       auto &nr_ctx
+         = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+       auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
+       rust_assert (res.has_value ());
+       variable_id = res.value ();
+      }
+    else
+      {
+       bool ok = ctx.resolver.lookup_resolved_name (
+         variable.get_mappings ().get_nodeid (), &variable_id);
+       rust_assert (ok);
+      }
     return ctx.place_db.lookup_variable (variable_id);
   }
 
@@ -425,9 +448,20 @@ protected: // HIR resolution helpers
     // Unlike variables,
     // functions do not have to be declared in PlaceDB before use.
     NodeId variable_id;
-    bool ok = ctx.resolver.lookup_resolved_name (
-      variable.get_mappings ().get_nodeid (), &variable_id);
-    rust_assert (ok);
+    if (flag_name_resolution_2_0)
+      {
+       auto &nr_ctx
+         = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+       auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
+       rust_assert (res.has_value ());
+       variable_id = res.value ();
+      }
+    else
+      {
+       bool ok = ctx.resolver.lookup_resolved_name (
+         variable.get_mappings ().get_nodeid (), &variable_id);
+       rust_assert (ok);
+      }
     if (ty->is<TyTy::FnType> ())
       return ctx.place_db.get_constant (ty);
     else