Skip to content

Commit

Permalink
Extract trait_may_define_assoc_type helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Nov 27, 2020
1 parent aa1cafd commit 30e933c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions compiler/rustc_typeck/src/astconv/mod.rs
Expand Up @@ -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);
}
}
Expand All @@ -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`.
///
Expand Down

0 comments on commit 30e933c

Please sign in to comment.