@@ -231,13 +231,21 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
231231
232232 let mut candidates = Vec :: new ( ) ;
233233 // LHS normalizes-to RHS
234- candidates. extend (
235- evaluate_normalizes_to ( self , alias_lhs, rhs, direction, Invert :: No ) . ok ( ) ,
236- ) ;
234+ candidates. extend ( evaluate_normalizes_to (
235+ self ,
236+ alias_lhs,
237+ rhs,
238+ direction,
239+ Invert :: No ,
240+ ) ) ;
237241 // RHS normalizes-to RHS
238- candidates. extend (
239- evaluate_normalizes_to ( self , alias_rhs, lhs, direction, Invert :: Yes ) . ok ( ) ,
240- ) ;
242+ candidates. extend ( evaluate_normalizes_to (
243+ self ,
244+ alias_rhs,
245+ lhs,
246+ direction,
247+ Invert :: Yes ,
248+ ) ) ;
241249 // Relate via substs
242250 let subst_relate_response = self . probe ( |ecx| {
243251 let span = tracing:: span!(
@@ -265,10 +273,18 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
265273
266274 if let Some ( merged) = self . try_merge_responses ( & candidates) {
267275 Ok ( merged)
268- } else if let Ok ( subst_relate_response) = subst_relate_response {
269- Ok ( subst_relate_response)
270276 } else {
271- self . flounder ( & candidates)
277+ // When relating two aliases and we have ambiguity, we prefer
278+ // relating the generic arguments of the aliases over normalizing
279+ // them. This is necessary for inference during typeck.
280+ //
281+ // As this is incomplete, we must not do so during coherence.
282+ match ( self . solver_mode ( ) , subst_relate_response) {
283+ ( SolverMode :: Normal , Ok ( response) ) => Ok ( response) ,
284+ ( SolverMode :: Normal , Err ( NoSolution ) ) | ( SolverMode :: Coherence , _) => {
285+ self . flounder ( & candidates)
286+ }
287+ }
272288 }
273289 }
274290 }
0 commit comments