[COMMITTED 19/83] gccrs: improve type path resolution to do the trait lookup directly
arthur.cohen@opensrcsec.com
arthur.cohen@opensrcsec.com
Wed Sep 16 12:29:38 GMT 2026
From: Philip Herron <herron.philip@googlemail.com>
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 <herron.philip@googlemail.com>
---
.../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 2e13ae4dd49..9a44fcebcc1 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 ad487208ce4..7e27343cd11 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;
--
2.50.1
More information about the Gcc-rust
mailing list