Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/ty/context/impl_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
// only want to consider types that *actually* unify with float/int vars.
fn for_each_relevant_impl<R: VisitorResult>(
self,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
trait_ref: ty::TraitRef<'tcx>,
mut f: impl FnMut(DefId) -> R,
) -> R {
macro_rules! ret {
Expand All @@ -554,6 +553,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
};
}

let trait_def_id = trait_ref.def_id;
let self_ty = trait_ref.self_ty();
let tcx = self;
let trait_impls = tcx.trait_impls_of(trait_def_id);
let mut consider_impls_for_simplified_type = |simp| {
Expand Down
38 changes: 17 additions & 21 deletions compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,28 +539,24 @@ where
candidates: &mut Vec<Candidate<I>>,
) -> Result<(), RerunNonErased> {
let cx = self.cx();
cx.for_each_relevant_impl(
goal.predicate.trait_def_id(cx),
goal.predicate.self_ty(),
|impl_def_id| -> Result<_, _> {
// For every `default impl`, there's always a non-default `impl`
// that will *also* apply. There's no reason to register a candidate
// for this impl, since it is *not* proof that the trait goal holds.
if cx.impl_is_default(impl_def_id) {
return Ok(());
}
match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
})
.map_err_to_rerun()?
{
Ok(candidate) => candidates.push(candidate),
Err(NoSolution) => {}
}
cx.for_each_relevant_impl(goal.predicate.trait_ref(cx), |impl_def_id| -> Result<_, _> {
// For every `default impl`, there's always a non-default `impl`
// that will *also* apply. There's no reason to register a candidate
// for this impl, since it is *not* proof that the trait goal holds.
if cx.impl_is_default(impl_def_id) {
return Ok(());
}
match G::consider_impl_candidate(self, goal, impl_def_id, |ecx, certainty| {
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
})
.map_err_to_rerun()?
{
Ok(candidate) => candidates.push(candidate),
Err(NoSolution) => {}
}

Ok(())
},
)
Ok(())
})
}

#[instrument(level = "trace", skip_all)]
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_next_trait_solver/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,13 +1246,9 @@ where
let self_ty = goal.predicate.self_ty();
let check_impls = || {
let mut disqualifying_impl = None;
self.cx().for_each_relevant_impl(
goal.predicate.def_id(),
goal.predicate.self_ty(),
|impl_def_id| {
disqualifying_impl = Some(impl_def_id);
},
);
self.cx().for_each_relevant_impl(goal.predicate.trait_ref, |impl_def_id| {
disqualifying_impl = Some(impl_def_id);
});
if let Some(def_id) = disqualifying_impl {
trace!(?def_id, ?goal, "disqualified auto-trait implementation");
// No need to actually consider the candidate here,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_type_ir/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::solve::{
AccessedOpaques, CanonicalInput, Certainty, ExternalConstraintsData, QueryResult, inspect,
};
use crate::visit::{Flags, TypeVisitable};
use crate::{self as ty, CanonicalParamEnvCacheEntry, search_graph};
use crate::{self as ty, CanonicalParamEnvCacheEntry, TraitRef, search_graph};

#[cfg_attr(feature = "nightly", rustc_diagnostic_item = "type_ir_interner")]
pub trait Interner:
Expand Down Expand Up @@ -398,8 +398,7 @@ pub trait Interner:

fn for_each_relevant_impl<R: VisitorResult>(
self,
trait_def_id: Self::TraitId,
self_ty: Self::Ty,
trait_ref: TraitRef<Self>,
f: impl FnMut(Self::ImplId) -> R,
) -> R;
fn for_each_blanket_impl<R: VisitorResult>(
Expand Down
Loading