Rollup merge of #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```
This commit is contained in:
nils 2023-01-11 17:30:53 +01:00 committed by GitHub
commit 16938915a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -131,8 +131,14 @@ fn consider_impl_candidate(
else {
return
};
let where_clause_bounds = tcx
.predicates_of(impl_def_id)
.instantiate(tcx, impl_substs)
.predicates
.into_iter()
.map(|pred| goal.with(tcx, pred));
let nested_goals = obligations.into_iter().map(|o| o.into()).collect();
let nested_goals = obligations.into_iter().map(|o| o.into()).chain(where_clause_bounds).collect();
let Ok(trait_ref_certainty) = acx.cx.evaluate_all(acx.infcx, nested_goals) else { return };
let Some(assoc_def) = fetch_eligible_assoc_item_def(

View File

@ -71,7 +71,9 @@ fn consider_impl_candidate(
goal: Goal<'tcx, TraitPredicate<'tcx>>,
impl_def_id: DefId,
) {
let impl_trait_ref = acx.cx.tcx.bound_impl_trait_ref(impl_def_id).unwrap();
let tcx = acx.cx.tcx;
let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap();
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
if iter::zip(goal.predicate.trait_ref.substs, impl_trait_ref.skip_binder().substs)
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
@ -81,7 +83,7 @@ fn consider_impl_candidate(
acx.infcx.probe(|_| {
let impl_substs = acx.infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
let impl_trait_ref = impl_trait_ref.subst(acx.cx.tcx, impl_substs);
let impl_trait_ref = impl_trait_ref.subst(tcx, impl_substs);
let Ok(InferOk { obligations, .. }) = acx
.infcx
@ -92,8 +94,15 @@ fn consider_impl_candidate(
else {
return
};
let where_clause_bounds = tcx
.predicates_of(impl_def_id)
.instantiate(tcx, impl_substs)
.predicates
.into_iter()
.map(|pred| goal.with(tcx, pred));
let nested_goals = obligations.into_iter().map(|o| o.into()).collect();
let nested_goals =
obligations.into_iter().map(|o| o.into()).chain(where_clause_bounds).collect();
let Ok(certainty) = acx.cx.evaluate_all(acx.infcx, nested_goals) else { return };
acx.try_insert_candidate(CandidateSource::Impl(impl_def_id), certainty);