From b4ae576793f4e9b176d2b668f8228414337279fb Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Wed, 9 Oct 2024 00:16:27 -0400 Subject: [PATCH] Fix name resolution 2.0 definition lookups in unsafe checker gcc/rust/ChangeLog: * checks/errors/rust-unsafe-checker.cc: Add includes. (UnsafeChecker::visit): Use 2.0 version of resolver when name resolution 2.0 is enabled. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery --- gcc/rust/checks/errors/rust-unsafe-checker.cc | 42 +++++++++++++++++-- gcc/testsuite/rust/compile/nr2/exclude | 6 --- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc index af3cd80245d1..3bf72428aadb 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.cc +++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc @@ -23,6 +23,10 @@ #include "rust-hir-item.h" #include "rust-attribute-values.h" #include "rust-system.h" +#include "rust-immutable-name-resolution-context.h" + +// for flag_name_resolution_2_0 +#include "options.h" namespace Rust { namespace HIR { @@ -216,8 +220,23 @@ UnsafeChecker::visit (PathInExpression &path) NodeId ast_node_id = path.get_mappings ().get_nodeid (); NodeId ref_node_id; - if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id)) - return; + if (flag_name_resolution_2_0) + { + auto &nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + auto resolved = nr_ctx.lookup (ast_node_id); + + if (!resolved.has_value ()) + return; + + ref_node_id = resolved.value (); + } + else + { + if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id)) + return; + } if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id)) { @@ -418,8 +437,23 @@ UnsafeChecker::visit (CallExpr &expr) // There are no unsafe types, and functions are defined in the name resolver. // If we can't find the name, then we're dealing with a type and should return // early. - if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id)) - return; + if (flag_name_resolution_2_0) + { + auto &nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + auto resolved = nr_ctx.lookup (ast_node_id); + + if (!resolved.has_value ()) + return; + + ref_node_id = resolved.value (); + } + else + { + if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id)) + return; + } if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id)) { diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index 450fc254452d..47d651b22bdf 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -191,12 +191,6 @@ traits9.rs type-bindings1.rs unconstrained_type_param.rs undeclared_label.rs -unsafe1.rs -unsafe11.rs -unsafe2.rs -unsafe3.rs -unsafe6.rs -unsafe7.rs use_1.rs use_2.rs v0-mangle1.rs