diff options
| author | Dániel Buga <bugadani@gmail.com> | 2020-10-09 16:56:09 +0200 |
|---|---|---|
| committer | Dániel Buga <bugadani@gmail.com> | 2020-10-09 16:56:09 +0200 |
| commit | 18318a9d848950680c12c17183f175c7c511c2ce (patch) | |
| tree | adb54e644a7a79952c348135d49240cd6002699a | |
| parent | 7993ddd89d8d2e0754bf9b12756573f56b76e254 (diff) | |
Reimplement for_each_relevant_impl on top of find_map...
| -rw-r--r-- | compiler/rustc_middle/src/ty/trait_def.rs | 47 |
1 files changed, 17 insertions, 30 deletions
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<T, F: FnMut(DefId) -> Option<T>>( + self, + def_id: DefId, + self_ty: Ty<'tcx>, + mut f: F, + ) -> Option<T> { 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 @@ -157,35 +173,6 @@ impl<'tcx> TyCtxt<'tcx> { 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<T, F: Fn(DefId) -> Option<T>>( - self, - def_id: DefId, - self_ty: Ty<'tcx>, - f: F, - ) -> Option<T> { - 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 { if let result @ Some(_) = f(impl_def_id) { return result; } |
