1
Fork 0

Rollup merge of #113901 - compiler-errors:only-bidi-norm, r=lcnr

Get rid of subst-relate incompleteness in new solver

We shouldn't need subst-relate if we have bidirectional-normalizes-to in the new solver.

The only potential issue may happen if we have an unconstrained projection like `<Wrapper<?0> as Trait>::Assoc == <Wrapper<T> as Trait>::Assoc` where they both normalize to something that doesn't mention any substs, which would possibly prefer `?0 = T` if we fall back to subst-relate. But I'd prefer if we remove incompleteness until we can determine some case where we need them, and the bidirectional-normalizes-to seems better to have in general.

I can update https://github.com/rust-lang/trait-system-refactor-initiative/issues/26 and https://github.com/rust-lang/trait-system-refactor-initiative/issues/25 once this lands.

r? `@lcnr`
This commit is contained in:
Matthias Krüger 2023-07-22 19:57:36 +02:00 committed by GitHub
commit 8f4b81b146
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,24 +66,27 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
Invert::Yes, Invert::Yes,
)); ));
// Relate via args // Relate via args
let subst_relate_response = self candidates.extend(
.assemble_subst_relate_candidate(param_env, alias_lhs, alias_rhs, direction); self.assemble_subst_relate_candidate(
candidates.extend(subst_relate_response); param_env, alias_lhs, alias_rhs, direction,
),
);
debug!(?candidates); debug!(?candidates);
if let Some(merged) = self.try_merge_responses(&candidates) { if let Some(merged) = self.try_merge_responses(&candidates) {
Ok(merged) Ok(merged)
} else { } else {
// When relating two aliases and we have ambiguity, we prefer // When relating two aliases and we have ambiguity, if both
// relating the generic arguments of the aliases over normalizing // aliases can be normalized to something, we prefer
// them. This is necessary for inference during typeck. // "bidirectionally normalizing" both of them within the same
// candidate.
//
// See <https://github.com/rust-lang/trait-system-refactor-initiative/issues/25>.
// //
// As this is incomplete, we must not do so during coherence. // As this is incomplete, we must not do so during coherence.
match self.solver_mode() { match self.solver_mode() {
SolverMode::Normal => { SolverMode::Normal => {
if let Ok(subst_relate_response) = subst_relate_response { if let Ok(bidirectional_normalizes_to_response) = self
Ok(subst_relate_response)
} else if let Ok(bidirectional_normalizes_to_response) = self
.assemble_bidirectional_normalizes_to_candidate( .assemble_bidirectional_normalizes_to_candidate(
param_env, lhs, rhs, direction, param_env, lhs, rhs, direction,
) )