diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 7207e5a179e..b2a8b33e4ff 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -51,7 +51,7 @@ use rustc_session::config::{BorrowckMode, CrateType, OutputFilenames}; use rustc_session::lint::{Level, Lint}; use rustc_session::Session; use rustc_span::source_map::MultiSpan; -use rustc_span::symbol::{kw, sym, Symbol}; +use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::{Layout, TargetDataLayout, VariantIdx}; use rustc_target::spec::abi; @@ -2085,6 +2085,16 @@ impl<'tcx> TyCtxt<'tcx> { self.mk_fn_ptr(sig.map_bound(|sig| ty::FnSig { unsafety: hir::Unsafety::Unsafe, ..sig })) } + /// 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`. + pub fn trait_may_define_assoc_type(self, trait_def_id: DefId, assoc_name: Ident) -> bool { + self.super_traits_of(trait_def_id).iter().any(|trait_did| { + self.associated_items(*trait_did) + .find_by_name_and_kind(self, assoc_name, ty::AssocKind::Type, *trait_did) + .is_some() + }) + } + /// Given a closure signature, returns an equivalent fn signature. Detuples /// and so forth -- so e.g., if we have a sig with `Fn<(u32, i32)>` then /// you would get a `fn(u32, i32)`. diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 4e87940efd3..3ec0919bb8a 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -909,7 +909,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 self.trait_may_define_assoc_type(trait_did, assoc_name) { + if self.tcx().trait_may_define_assoc_type(trait_did, assoc_name) { result.push(ast_bound); } } @@ -919,17 +919,6 @@ 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 { - self.tcx().super_traits_of(trait_def_id).iter().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`. /// diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index d7da7f2a5d9..8d5e518c151 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -654,17 +654,7 @@ impl ItemCtxt<'tcx> { hir::GenericBound::Trait(poly_trait_ref, _) => { let trait_ref = &poly_trait_ref.trait_ref; if let Some(trait_did) = trait_ref.trait_def_id() { - self.tcx.super_traits_of(trait_did).iter().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() - }) + self.tcx.trait_may_define_assoc_type(trait_did, assoc_name) } else { false }