return item_refs;
}
+ void get_trait_items_and_supers (
+ std::vector<const TraitItemReference *> &result) const
+ {
+ for (const auto &item : item_refs)
+ result.push_back (&item);
+
+ for (const auto &super_trait : super_traits)
+ super_trait->get_trait_items_and_supers (result);
+ }
+
void on_resolved ()
{
for (auto &item : item_refs)
return trait_substs;
}
+ bool satisfies_bound (const TraitReference &reference) const
+ {
+ if (is_equal (reference))
+ return true;
+
+ for (const auto &super_trait : super_traits)
+ {
+ if (super_trait->satisfies_bound (reference))
+ return true;
+ }
+
+ return false;
+ }
+
private:
const HIR::Trait *hir_trait_ref;
std::vector<TraitItemReference> item_refs;
BaseType::satisfies_bound (const TypeBoundPredicate &predicate) const
{
const Resolver::TraitReference *query = predicate.get ();
- for (auto &bound : specified_bounds)
+ for (const auto &bound : specified_bounds)
{
const Resolver::TraitReference *item = bound.get ();
- bool found = item->get_mappings ().get_defid ()
- == query->get_mappings ().get_defid ();
- if (found)
+ if (item->satisfies_bound (*query))
return true;
}
auto probed = Resolver::TypeBoundsProbe::Probe (this);
- for (auto &b : probed)
+ for (const auto &b : probed)
{
const Resolver::TraitReference *bound = b.first;
- bool found = bound->get_mappings ().get_defid ()
- == query->get_mappings ().get_defid ();
- if (found)
+ if (bound->satisfies_bound (*query))
return true;
}
rust_error_at (r,
"bounds not satisfied for %s %<%s%> is not satisfied",
other.get_name ().c_str (), missing_preds.c_str ());
- // rust_assert (!emit_error);
}
}
for (auto &bound : get_specified_bounds ())
{
const Resolver::TraitReference *trait = bound.get ();
- for (auto &item : trait->get_trait_items ())
- {
- if (item.get_trait_item_type ()
- == Resolver::TraitItemReference::TraitItemType::FN
- && item.is_object_safe ())
- items.push_back ({&item, &bound});
- }
+ std::vector<const Resolver::TraitItemReference *> trait_items;
+ trait->get_trait_items_and_supers (trait_items);
- for (auto &super_trait : trait->get_super_traits ())
+ for (auto &item : trait_items)
{
- for (auto &item : super_trait->get_trait_items ())
- {
- if (item.get_trait_item_type ()
- == Resolver::TraitItemReference::TraitItemType::FN
- && item.is_object_safe ())
- items.push_back ({&item, &bound});
- }
+ if (item->get_trait_item_type ()
+ == Resolver::TraitItemReference::TraitItemType::FN
+ && item->is_object_safe ())
+ items.push_back ({item, &bound});
}
}
return items;