]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use name resolver 2.0 in VisibilityResolver
authorOwen Avery <powerboat9.gamer@gmail.com>
Tue, 5 Nov 2024 02:52:14 +0000 (21:52 -0500)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Tue, 5 Nov 2024 10:11:25 +0000 (10:11 +0000)
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.gamer@gmail.com>
gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc

index 7110883750f5561bf8b5e1f42bcd21cf27b06be0..f11b56af34ca8e96ef45eea581694f9ace5a3d20 100644 (file)
 #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;