diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index 5599216c316..86476dffc03 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -123,10 +123,26 @@ impl<'tcx> TyCtxt<'tcx> { self_ty: Ty<'tcx>, mut f: F, ) { + let _: Option<()> = self.find_map_relevant_impl(def_id, self_ty, |did| { + f(did); + None + }); + } + + /// Applies function to every impl that could possibly match the self type `self_ty` and returns + /// the first non-none value. + pub fn find_map_relevant_impl Option>( + self, + def_id: DefId, + self_ty: Ty<'tcx>, + mut f: F, + ) -> Option { let impls = self.trait_impls_of(def_id); for &impl_def_id in impls.blanket_impls.iter() { - f(impl_def_id); + if let result @ Some(_) = f(impl_def_id) { + return result; + } } // simplify_type(.., false) basically replaces type parameters and @@ -154,35 +170,6 @@ impl<'tcx> TyCtxt<'tcx> { // blanket and non-blanket impls, and compare them separately. // // I think we'll cross that bridge when we get to it. - if let Some(simp) = fast_reject::simplify_type(self, self_ty, true) { - if let Some(impls) = impls.non_blanket_impls.get(&simp) { - for &impl_def_id in impls { - f(impl_def_id); - } - } - } else { - for &impl_def_id in impls.non_blanket_impls.values().flatten() { - f(impl_def_id); - } - } - } - - /// Applies function to every impl that could possibly match the self type `self_ty` and returns - /// the first non-none value. - pub fn find_map_relevant_impl Option>( - self, - def_id: DefId, - self_ty: Ty<'tcx>, - f: F, - ) -> Option { - let impls = self.trait_impls_of(def_id); - - for &impl_def_id in impls.blanket_impls.iter() { - if let result @ Some(_) = f(impl_def_id) { - return result; - } - } - if let Some(simp) = fast_reject::simplify_type(self, self_ty, true) { if let Some(impls) = impls.non_blanket_impls.get(&simp) { for &impl_def_id in impls {