https://gcc.gnu.org/g:31aaed7018cc0734d51a945fc03ac8365e641cac
commit r17-4296-g31aaed7018cc0734d51a945fc03ac8365e641cac Author: Philip Herron <[email protected]> Date: Sun Aug 23 21:45:24 2026 +0100 gccrs: improve type path resolution to do the trait lookup directly The code used to work by accident that the type bounds probe already setup the type checked trait before hand so the lookup's just worked by accident. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): dp trait lookup * typecheck/rust-tyty.cc (BaseType::satisfies_bound): add filter Signed-off-by: Philip Herron <[email protected]> Diff: --- gcc/rust/typecheck/rust-hir-type-check-path.cc | 25 +++++++++++++++++++++---- gcc/rust/typecheck/rust-tyty.cc | 4 +++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index 2e13ae4dd494..9a44fcebcc13 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -208,11 +208,28 @@ TypeCheckExpr::visit (HIR::PathInExpression &expr) else { TyTy::BaseType *resolved = nullptr; - context->lookup_type (*hir_id, &resolved); - - rust_assert (resolved); + auto trait_item = mappings.lookup_hir_trait_item (*hir_id); + if (trait_item.has_value ()) + { + HIR::Trait *trait = mappings.lookup_trait_item_mapping (*hir_id); + rust_assert (trait != nullptr); + + TraitReference *trait_ref = TraitResolver::Resolve (*trait); + if (trait_ref->is_error ()) + return; + + TraitItemReference *trait_item_ref = nullptr; + bool ok = trait_ref->lookup_hir_trait_item (**trait_item, + &trait_item_ref); + rust_assert (ok); + resolved = trait_item_ref->get_tyty (); + } + else if (!query_type (*hir_id, &resolved)) + return; - query_type (*hir_id, &infered); + if (resolved == nullptr + || resolved->get_kind () == TyTy::TypeKind::ERROR) + return; infered = SubstMapper::InferSubst (resolved, expr.get_locus ()); } diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index ad487208ce4a..7e27343cd112 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -395,7 +395,9 @@ BaseType::satisfies_bound (const TypeBoundPredicate &predicate, bool emit_error) return true; bool satisfied = false; - auto probed = Resolver::TypeBoundsProbe::Probe (this); + auto tref = predicate.get (); + auto probed + = Resolver::TypeBoundsProbe::Probe (this, tref->get_hir_trait_ref ()); for (const auto &b : probed) { const Resolver::TraitReference *bound = b.first;
