Reimplement for_each_relevant_impl on top of find_map...
This commit is contained in:
parent
7993ddd89d
commit
18318a9d84
1 changed files with 17 additions and 30 deletions
|
@ -123,10 +123,26 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
mut f: F,
|
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);
|
let impls = self.trait_impls_of(def_id);
|
||||||
|
|
||||||
for &impl_def_id in impls.blanket_impls.iter() {
|
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
|
// 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.
|
// blanket and non-blanket impls, and compare them separately.
|
||||||
//
|
//
|
||||||
// I think we'll cross that bridge when we get to it.
|
// 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(simp) = fast_reject::simplify_type(self, self_ty, true) {
|
||||||
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
|
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
|
||||||
for &impl_def_id in impls {
|
for &impl_def_id in impls {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue