Skip to content

Commit

Permalink
Rollup merge of #111987 - lcnr:alias-relate-coherence, r=BoxyUwU
Browse files Browse the repository at this point in the history
do not prefer substs relate during coherence

r? ```@compiler-errors```
  • Loading branch information
matthiaskrgr authored May 26, 2023
2 parents a81ef8a + b6b9611 commit dfdbf1b
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions compiler/rustc_trait_selection/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,21 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {

let mut candidates = Vec::new();
// LHS normalizes-to RHS
candidates.extend(
evaluate_normalizes_to(self, alias_lhs, rhs, direction, Invert::No).ok(),
);
candidates.extend(evaluate_normalizes_to(
self,
alias_lhs,
rhs,
direction,
Invert::No,
));
// RHS normalizes-to RHS
candidates.extend(
evaluate_normalizes_to(self, alias_rhs, lhs, direction, Invert::Yes).ok(),
);
candidates.extend(evaluate_normalizes_to(
self,
alias_rhs,
lhs,
direction,
Invert::Yes,
));
// Relate via substs
let subst_relate_response = self.probe(|ecx| {
let span = tracing::span!(
Expand Down Expand Up @@ -265,10 +273,18 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {

if let Some(merged) = self.try_merge_responses(&candidates) {
Ok(merged)
} else if let Ok(subst_relate_response) = subst_relate_response {
Ok(subst_relate_response)
} else {
self.flounder(&candidates)
// When relating two aliases and we have ambiguity, we prefer
// relating the generic arguments of the aliases over normalizing
// them. This is necessary for inference during typeck.
//
// As this is incomplete, we must not do so during coherence.
match (self.solver_mode(), subst_relate_response) {
(SolverMode::Normal, Ok(response)) => Ok(response),
(SolverMode::Normal, Err(NoSolution)) | (SolverMode::Coherence, _) => {
self.flounder(&candidates)
}
}
}
}
}
Expand Down

0 comments on commit dfdbf1b

Please sign in to comment.