Skip to content

Commit

Permalink
clean-up for_each_impl to use all_impls
Browse files Browse the repository at this point in the history
handle `impls_for_ref_x` and reduce duplication when iterating over all impls.

also: use it in `for_each_relevant_impl_treating_projections`
  • Loading branch information
lqd committed May 31, 2023
1 parent a9d7810 commit f2b58f3
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions compiler/rustc_middle/src/ty/trait_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,10 @@ impl<'tcx> TraitDef {

impl<'tcx> TyCtxt<'tcx> {
/// `trait_def_id` MUST BE the `DefId` of a trait.
pub fn for_each_impl<F: FnMut(DefId)>(self, trait_def_id: DefId, mut f: F) {
let impls = self.trait_impls_of(trait_def_id);

for &impl_def_id in impls.blanket_impls.iter() {
pub fn for_each_impl(self, trait_def_id: DefId, mut f: impl FnMut(DefId)) {
for impl_def_id in self.all_impls(trait_def_id) {
f(impl_def_id);
}

for v in impls.non_blanket_impls.values() {
for &impl_def_id in v {
f(impl_def_id);
}
}
}

/// Iterate over every impl that could possibly match the self type `self_ty`.
Expand Down Expand Up @@ -190,9 +182,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
}
} else {
for impl_def_id in self.all_impls(trait_def_id) {
f(impl_def_id);
}
self.for_each_impl(trait_def_id, f);
}
}

Expand Down

0 comments on commit f2b58f3

Please sign in to comment.