From: Philip Herron <[email protected]>

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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/e28ff01a07f04274968154a61944a77c165a28d5

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4816

 .../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 2e13ae4dd..9a44fcebc 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 ad487208c..7e27343cd 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.55.0

Reply via email to