Skip to content

Commit b9e349a

Browse files
committed
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.
1 parent 45395cf commit b9e349a

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

gcc/rust/typecheck/rust-tyty-bounds.cc

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,16 +754,34 @@ size_t
754754
TypeBoundPredicate::get_num_associated_bindings () const
755755
{
756756
size_t count = 0;
757+
758+
get_trait_hierachy ([&count] (const Resolver::TraitReference &ref) {
759+
for (const auto &trait_item : ref.get_trait_items ())
760+
{
761+
bool is_associated_type
762+
= trait_item.get_trait_item_type ()
763+
== Resolver::TraitItemReference::TraitItemType::TYPE;
764+
if (is_associated_type)
765+
count++;
766+
}
767+
});
768+
769+
return count;
770+
}
771+
772+
void
773+
TypeBoundPredicate::get_trait_hierachy (
774+
std::function<void (const Resolver::TraitReference &)> callback) const
775+
{
757776
auto trait_ref = get ();
758-
for (const auto &trait_item : trait_ref->get_trait_items ())
777+
callback (*trait_ref);
778+
779+
for (auto &super : super_traits)
759780
{
760-
bool is_associated_type
761-
= trait_item.get_trait_item_type ()
762-
== Resolver::TraitItemReference::TraitItemType::TYPE;
763-
if (is_associated_type)
764-
count++;
781+
const auto &super_trait_ref = *super.get ();
782+
callback (super_trait_ref);
783+
super.get_trait_hierachy (callback);
765784
}
766-
return count;
767785
}
768786

769787
TypeBoundPredicateItem

gcc/rust/typecheck/rust-tyty.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ class TypeBoundPredicate : public SubstitutionRef
593593

594594
TypeBoundPredicate (mark_is_error);
595595

596+
void get_trait_hierachy (
597+
std::function<void (const Resolver::TraitReference &)> callback) const;
598+
596599
DefId reference;
597600
location_t locus;
598601
bool error_flag;

0 commit comments

Comments
 (0)