From 8a6d24d5a398137a75a2bc2225095b1501e50606 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Sat, 26 Oct 2024 19:43:11 -0400 Subject: [PATCH] Use name resolution 2.0 in TraitResolver gcc/rust/ChangeLog: * typecheck/rust-hir-trait-resolve.cc: Add includes. (TraitResolver::resolve_path_to_trait): Use name resolution 2.0 resolver when enabled. Signed-off-by: Owen Avery --- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 24 ++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 3e41d2f5a61..3e66e7591c7 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -20,6 +20,10 @@ #include "rust-hir-type-check-expr.h" #include "rust-substitution-mapper.h" #include "rust-type-util.h" +#include "rust-immutable-name-resolution-context.h" + +// used for flag_name_resolution_2_0 +#include "options.h" namespace Rust { namespace Resolver { @@ -110,8 +114,24 @@ TraitResolver::resolve_path_to_trait (const HIR::TypePath &path, HIR::Trait **resolved) const { NodeId ref; - if (!resolver->lookup_resolved_type (path.get_mappings ().get_nodeid (), - &ref)) + bool ok; + if (flag_name_resolution_2_0) + { + auto &nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + auto ref_opt = nr_ctx.lookup (path.get_mappings ().get_nodeid ()); + + if ((ok = ref_opt.has_value ())) + ref = *ref_opt; + } + else + { + ok = resolver->lookup_resolved_type (path.get_mappings ().get_nodeid (), + &ref); + } + + if (!ok) { rust_error_at (path.get_locus (), "Failed to resolve path to node-id"); return false;