https://gcc.gnu.org/g:76fcedad2f95ac35e2a4c8aa2a45a75e32e80a61

commit 76fcedad2f95ac35e2a4c8aa2a45a75e32e80a61
Author: Owen Avery <powerboat9.ga...@gmail.com>
Date:   Mon Nov 4 21:52:14 2024 -0500

    Use name resolver 2.0 in VisibilityResolver
    
    gcc/rust/ChangeLog:
    
            * checks/errors/privacy/rust-visibility-resolver.cc:
            Add includes.
            (VisibilityResolver::resolve_module_path): Use name resolver 2.0
            (when enabled) to lookup path resolutions.
    
    Signed-off-by: Owen Avery <powerboat9.ga...@gmail.com>

Diff:
---
 .../errors/privacy/rust-visibility-resolver.cc      | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc 
b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
index 7110883750f5..f11b56af34ca 100644
--- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
+++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
@@ -20,6 +20,10 @@
 #include "rust-ast.h"
 #include "rust-hir.h"
 #include "rust-hir-item.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
 
 namespace Rust {
 namespace Privacy {
@@ -61,7 +65,22 @@ VisibilityResolver::resolve_module_path (const 
HIR::SimplePath &restriction,
             "cannot use non-module path as privacy restrictor");
 
   NodeId ref_node_id = UNKNOWN_NODEID;
-  if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+  if (flag_name_resolution_2_0)
+    {
+      auto &nr_ctx
+       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+      if (auto id = nr_ctx.lookup (ast_node_id))
+       {
+         ref_node_id = *id;
+       }
+      else
+       {
+         invalid_path.emit ();
+         return false;
+       }
+    }
+  else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
     {
       invalid_path.emit ();
       return false;

Reply via email to