summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/ty/trait_def.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_middle/src/ty/trait_def.rs')
-rw-r--r--compiler/rustc_middle/src/ty/trait_def.rs62
1 files changed, 18 insertions, 44 deletions
diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs
index 6747da7ab..e61037e5e 100644
--- a/compiler/rustc_middle/src/ty/trait_def.rs
+++ b/compiler/rustc_middle/src/ty/trait_def.rs
@@ -139,40 +139,6 @@ impl<'tcx> TyCtxt<'tcx> {
treat_projections: TreatProjections,
mut f: impl FnMut(DefId),
) {
- let _: Option<()> =
- self.find_map_relevant_impl(trait_def_id, self_ty, treat_projections, |did| {
- f(did);
- None
- });
- }
-
- /// `trait_def_id` MUST BE the `DefId` of a trait.
- pub fn non_blanket_impls_for_ty(
- self,
- trait_def_id: DefId,
- self_ty: Ty<'tcx>,
- ) -> impl Iterator<Item = DefId> + 'tcx {
- let impls = self.trait_impls_of(trait_def_id);
- if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey) {
- if let Some(impls) = impls.non_blanket_impls.get(&simp) {
- return impls.iter().copied();
- }
- }
-
- [].iter().copied()
- }
-
- /// Applies function to every impl that could possibly match the self type `self_ty` and returns
- /// the first non-none value.
- ///
- /// `trait_def_id` MUST BE the `DefId` of a trait.
- pub fn find_map_relevant_impl<T>(
- self,
- trait_def_id: DefId,
- self_ty: Ty<'tcx>,
- treat_projections: TreatProjections,
- mut f: impl FnMut(DefId) -> Option<T>,
- ) -> Option<T> {
// FIXME: This depends on the set of all impls for the trait. That is
// unfortunate wrt. incremental compilation.
//
@@ -181,9 +147,7 @@ impl<'tcx> TyCtxt<'tcx> {
let impls = self.trait_impls_of(trait_def_id);
for &impl_def_id in impls.blanket_impls.iter() {
- if let result @ Some(_) = f(impl_def_id) {
- return result;
- }
+ f(impl_def_id);
}
// Note that we're using `TreatParams::ForLookup` to query `non_blanket_impls` while using
@@ -199,20 +163,30 @@ impl<'tcx> TyCtxt<'tcx> {
if let Some(simp) = fast_reject::simplify_type(self, self_ty, treat_params) {
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;
- }
+ f(impl_def_id);
}
}
} else {
for &impl_def_id in impls.non_blanket_impls.values().flatten() {
- if let result @ Some(_) = f(impl_def_id) {
- return result;
- }
+ f(impl_def_id);
}
}
+ }
- None
+ /// `trait_def_id` MUST BE the `DefId` of a trait.
+ pub fn non_blanket_impls_for_ty(
+ self,
+ trait_def_id: DefId,
+ self_ty: Ty<'tcx>,
+ ) -> impl Iterator<Item = DefId> + 'tcx {
+ let impls = self.trait_impls_of(trait_def_id);
+ if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey) {
+ if let Some(impls) = impls.non_blanket_impls.get(&simp) {
+ return impls.iter().copied();
+ }
+ }
+
+ [].iter().copied()
}
/// Returns an iterator containing all impls for `trait_def_id`.