Skip to content

Commit 7aa788f

Browse files
authored
Rollup merge of rust-lang#106397 - compiler-errors:new-solver-impl-wc, r=lcnr
Check `impl`'s `where` clauses in `consider_impl_candidate` in experimental solver Check impl's nested predicates as part of the recursive evaluate in `consider_impl_candidate`. <sub>Unless, for some reason, these are intentionally **not** checked here -- in which case, I really don't understand where they're being checked...<sub> r? ``@lcnr``
2 parents 368dacc + 36ee66c commit 7aa788f

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Diff for: compiler/rustc_trait_selection/src/solve/project_goals.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
131131
else {
132132
return
133133
};
134-
135-
let nested_goals = obligations.into_iter().map(|o| o.into()).collect();
134+
let where_clause_bounds = tcx
135+
.predicates_of(impl_def_id)
136+
.instantiate(tcx, impl_substs)
137+
.predicates
138+
.into_iter()
139+
.map(|pred| goal.with(tcx, pred));
140+
141+
let nested_goals = obligations.into_iter().map(|o| o.into()).chain(where_clause_bounds).collect();
136142
let Ok(trait_ref_certainty) = acx.cx.evaluate_all(acx.infcx, nested_goals) else { return };
137143

138144
let Some(assoc_def) = fetch_eligible_assoc_item_def(

Diff for: compiler/rustc_trait_selection/src/solve/trait_goals.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
7171
goal: Goal<'tcx, TraitPredicate<'tcx>>,
7272
impl_def_id: DefId,
7373
) {
74-
let impl_trait_ref = acx.cx.tcx.bound_impl_trait_ref(impl_def_id).unwrap();
74+
let tcx = acx.cx.tcx;
75+
76+
let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap();
7577
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
7678
if iter::zip(goal.predicate.trait_ref.substs, impl_trait_ref.skip_binder().substs)
7779
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
@@ -81,7 +83,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
8183

8284
acx.infcx.probe(|_| {
8385
let impl_substs = acx.infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
84-
let impl_trait_ref = impl_trait_ref.subst(acx.cx.tcx, impl_substs);
86+
let impl_trait_ref = impl_trait_ref.subst(tcx, impl_substs);
8587

8688
let Ok(InferOk { obligations, .. }) = acx
8789
.infcx
@@ -92,8 +94,15 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
9294
else {
9395
return
9496
};
95-
96-
let nested_goals = obligations.into_iter().map(|o| o.into()).collect();
97+
let where_clause_bounds = tcx
98+
.predicates_of(impl_def_id)
99+
.instantiate(tcx, impl_substs)
100+
.predicates
101+
.into_iter()
102+
.map(|pred| goal.with(tcx, pred));
103+
104+
let nested_goals =
105+
obligations.into_iter().map(|o| o.into()).chain(where_clause_bounds).collect();
97106

98107
let Ok(certainty) = acx.cx.evaluate_all(acx.infcx, nested_goals) else { return };
99108
acx.try_insert_candidate(CandidateSource::Impl(impl_def_id), certainty);

0 commit comments

Comments
 (0)