From e7de54ddae5de2d38495dc98c3dd8a31a5092f62 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Tue, 15 Oct 2024 15:34:06 -0400 Subject: [PATCH] Use name resolver 2.0 in pattern checker gcc/rust/ChangeLog: * checks/errors/rust-hir-pattern-analysis.cc: Add includes. (PatternChecker::visit): Use name resolver 2.0 when enabled. Signed-off-by: Owen Avery --- .../checks/errors/rust-hir-pattern-analysis.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc index fdbc6e8d2ec0..f46f429e9306 100644 --- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc +++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc @@ -26,6 +26,10 @@ #include "rust-mapping-common.h" #include "rust-system.h" #include "rust-tyty.h" +#include "rust-immutable-name-resolution-context.h" + +// for flag_name_resolution_2_0 +#include "options.h" namespace Rust { namespace Analysis { @@ -234,7 +238,17 @@ PatternChecker::visit (CallExpr &expr) NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid (); NodeId ref_node_id; - 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 + return; + } + 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))