https://gcc.gnu.org/g:8ddeba50f47ec645eddf03d3fd9824acbf410c0a
commit r16-2888-g8ddeba50f47ec645eddf03d3fd9824acbf410c0a Author: Philip Herron <herron.phi...@googlemail.com> Date: Sat Jun 21 14:58:49 2025 +0100 gccrs: Fix bug with bad type bindings not looking at super traits When resolving type bounds, we need to examine super traits to properly determine if type bindings are valid in the current context. gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc: Check super traits for type bindings. * typecheck/rust-tyty.h: Add helper methods for bound checking. Diff: --- gcc/rust/typecheck/rust-tyty-bounds.cc | 32 +++++++++++++++++++++++++------- gcc/rust/typecheck/rust-tyty.h | 3 +++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index a36f7712dac4..f5b18004c187 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -754,16 +754,34 @@ size_t TypeBoundPredicate::get_num_associated_bindings () const { size_t count = 0; + + get_trait_hierachy ([&count] (const Resolver::TraitReference &ref) { + for (const auto &trait_item : ref.get_trait_items ()) + { + bool is_associated_type + = trait_item.get_trait_item_type () + == Resolver::TraitItemReference::TraitItemType::TYPE; + if (is_associated_type) + count++; + } + }); + + return count; +} + +void +TypeBoundPredicate::get_trait_hierachy ( + std::function<void (const Resolver::TraitReference &)> callback) const +{ auto trait_ref = get (); - for (const auto &trait_item : trait_ref->get_trait_items ()) + callback (*trait_ref); + + for (auto &super : super_traits) { - bool is_associated_type - = trait_item.get_trait_item_type () - == Resolver::TraitItemReference::TraitItemType::TYPE; - if (is_associated_type) - count++; + const auto &super_trait_ref = *super.get (); + callback (super_trait_ref); + super.get_trait_hierachy (callback); } - return count; } TypeBoundPredicateItem diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index c759521090da..e8ddd3e1d91d 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -593,6 +593,9 @@ private: TypeBoundPredicate (mark_is_error); + void get_trait_hierachy ( + std::function<void (const Resolver::TraitReference &)> callback) const; + DefId reference; location_t locus; bool error_flag;