https://gcc.gnu.org/g:df155b8713d879168e9bd39dd12a5dc3ff76a6e5
commit r17-4294-gdf155b8713d879168e9bd39dd12a5dc3ff76a6e5 Author: Philip Herron <[email protected]> Date: Sun Aug 23 21:15:55 2026 +0100 gccrs: Add explicitly filtering for is bound satisified gcc/rust/ChangeLog: * typecheck/rust-hir-type-bounds.h: optional trait arg * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): likewise (TypeBoundsProbe::Probe): likewise (TypeBoundsProbe::is_bound_satisfied_for_type): use specified trait (TypeBoundsProbe::scan): try to scan for indexed traits Signed-off-by: Philip Herron <[email protected]> Diff: --- gcc/rust/typecheck/rust-hir-type-bounds.h | 5 +++-- gcc/rust/typecheck/rust-tyty-bounds.cc | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-bounds.h b/gcc/rust/typecheck/rust-hir-type-bounds.h index bede694061d3..3dbc47ec78fa 100644 --- a/gcc/rust/typecheck/rust-hir-type-bounds.h +++ b/gcc/rust/typecheck/rust-hir-type-bounds.h @@ -30,7 +30,7 @@ class TypeBoundsProbe : public TypeCheckBase { public: static std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> - Probe (TyTy::BaseType *receiver); + Probe (TyTy::BaseType *receiver, const HIR::Trait *specified_trait = nullptr); static bool is_bound_satisfied_for_type (TyTy::BaseType *receiver, TraitReference *ref); @@ -46,9 +46,10 @@ private: void assemble_builtin_candidate (LangItem::Kind item); private: - TypeBoundsProbe (TyTy::BaseType *receiver); + TypeBoundsProbe (TyTy::BaseType *receiver, const HIR::Trait *specified_trait); TyTy::BaseType *receiver; + const HIR::Trait *specified_trait; std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> trait_references; }; diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 21a55ac6c488..86aa06d2706d 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -26,14 +26,16 @@ namespace Rust { namespace Resolver { -TypeBoundsProbe::TypeBoundsProbe (TyTy::BaseType *receiver) - : TypeCheckBase (), receiver (receiver) +TypeBoundsProbe::TypeBoundsProbe (TyTy::BaseType *receiver, + const HIR::Trait *specified_trait) + : TypeCheckBase (), receiver (receiver), specified_trait (specified_trait) {} std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> -TypeBoundsProbe::Probe (TyTy::BaseType *receiver) +TypeBoundsProbe::Probe (TyTy::BaseType *receiver, + const HIR::Trait *specified_trait) { - TypeBoundsProbe probe (receiver); + TypeBoundsProbe probe (receiver, specified_trait); probe.scan (); return probe.trait_references; } @@ -50,7 +52,7 @@ TypeBoundsProbe::is_bound_satisfied_for_type (TyTy::BaseType *receiver, } std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> bounds - = Probe (receiver); + = Probe (receiver, ref->get_hir_trait_ref ()); for (auto &bound : bounds) { const TraitReference *b = bound.first; @@ -95,10 +97,15 @@ TypeBoundsProbe::scan () { std::vector<std::pair<HIR::TypePath *, HIR::ImplBlock *>> possible_trait_paths; - mappings.iterate_impl_blocks ( - [&] (HirId id, HIR::ImplBlock *impl) mutable -> bool { - return process_impl_block (id, impl, possible_trait_paths); - }); + auto process_impl = [&] (HirId id, HIR::ImplBlock *impl) mutable -> bool { + return process_impl_block (id, impl, possible_trait_paths); + }; + + if (specified_trait == nullptr) + mappings.iterate_impl_blocks (process_impl); + else + mappings.iterate_trait_impl_blocks ( + specified_trait->get_mappings ().get_nodeid (), process_impl); for (auto &path : possible_trait_paths) {
