Extract trait_may_define_assoc_type helper function

This commit is contained in:
Santiago Pastorino 2020-11-20 17:57:44 -03:00
parent aa1cafd407
commit 30e933cd79
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF

View file

@ -910,17 +910,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
for ast_bound in ast_bounds {
if let Some(trait_ref) = ast_bound.trait_ref() {
if let Some(trait_did) = trait_ref.trait_def_id() {
if super_traits_of(self.tcx(), trait_did).any(|trait_did| {
self.tcx()
.associated_items(trait_did)
.find_by_name_and_kind(
self.tcx(),
assoc_name,
ty::AssocKind::Type,
trait_did,
)
.is_some()
}) {
if self.trait_may_define_assoc_type(trait_did, assoc_name) {
result.push(ast_bound);
}
}
@ -930,6 +920,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.compute_bounds(param_ty, &result, sized_by_default, span)
}
/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name`
/// returns true if the `trait_def_id` defines an associated item of name `assoc_name`.
fn trait_may_define_assoc_type(&self, trait_def_id: DefId, assoc_name: Ident) -> bool {
super_traits_of(self.tcx(), trait_def_id).any(|trait_did| {
self.tcx()
.associated_items(trait_did)
.find_by_name_and_kind(self.tcx(), assoc_name, ty::AssocKind::Type, trait_did)
.is_some()
})
}
/// Given an HIR binding like `Item = Foo` or `Item: Foo`, pushes the corresponding predicates
/// onto `bounds`.
///