about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2020-11-20 17:57:44 -0300
committerSantiago Pastorino <spastorino@gmail.com>2020-11-27 11:23:49 -0300
commit30e933cd794b90d2ea9164112dcf20c23c1eba5f (patch)
treeef1e30d17aee4f10a81df605240eb2ee94bd8c93
parentaa1cafd4079c9f246d495addd6c23cc47b266a8b (diff)
downloadrust-30e933cd794b90d2ea9164112dcf20c23c1eba5f.tar.gz
rust-30e933cd794b90d2ea9164112dcf20c23c1eba5f.zip
Extract trait_may_define_assoc_type helper function
-rw-r--r--compiler/rustc_typeck/src/astconv/mod.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs
index f7eb6720e1e..3cb85250e2a 100644
--- a/compiler/rustc_typeck/src/astconv/mod.rs
+++ b/compiler/rustc_typeck/src/astconv/mod.rs
@@ -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`.
     ///