Reimplement for_each_relevant_impl on top of find_map...
This commit is contained in:
parent
7993ddd89d
commit
18318a9d84
@ -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
|
||||
@ -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<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 {
|
||||
|
Loading…
Reference in New Issue
Block a user