https://gcc.gnu.org/g:dfc026ce0acf9a24f14c3ff1c019a35abfee2c27

commit dfc026ce0acf9a24f14c3ff1c019a35abfee2c27
Author: Owen Avery <powerboat9.ga...@gmail.com>
Date:   Fri May 9 18:02:29 2025 -0400

    nr2.0: Fix borrow checking
    
    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.ga...@gmail.com>

Diff:
---
 .../errors/borrowck/rust-bir-builder-internal.h    | 54 ++++++++++++++++++----
 1 file changed, 44 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
index 8de6b8b00a91..f636bda7e648 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -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

Reply via email to