@@ -13,7 +13,7 @@ use rustc_middle::bug;
1313use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
1414use rustc_middle:: ty:: { self , TyCtxt } ;
1515use rustc_next_trait_solver:: solve:: { GenerateProofTree , HasChanged , SolverDelegateEvalExt as _} ;
16- use tracing:: instrument;
16+ use tracing:: { instrument, trace } ;
1717
1818use super :: Certainty ;
1919use super :: delegate:: SolverDelegate ;
@@ -402,6 +402,7 @@ impl<'tcx> BestObligation<'tcx> {
402402 nested_goal. source( ) ,
403403 GoalSource :: ImplWhereBound
404404 | GoalSource :: InstantiateHigherRanked
405+ | GoalSource :: AliasWellFormed
405406 ) && match self . consider_ambiguities {
406407 true => {
407408 matches ! (
@@ -416,6 +417,13 @@ impl<'tcx> BestObligation<'tcx> {
416417 } )
417418 } ) ;
418419 }
420+
421+ // Prefer a non-rigid candidate if there is one.
422+ if candidates. len ( ) > 1 {
423+ candidates. retain ( |candidate| {
424+ !matches ! ( candidate. kind( ) , inspect:: ProbeKind :: RigidAlias { .. } )
425+ } ) ;
426+ }
419427 }
420428 }
421429
@@ -430,8 +438,11 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
430438 self . obligation . cause . span
431439 }
432440
441+ #[ instrument( level = "trace" , skip( self , goal) , fields( goal = ?goal. goal( ) ) ) ]
433442 fn visit_goal ( & mut self , goal : & inspect:: InspectGoal < ' _ , ' tcx > ) -> Self :: Result {
434443 let candidates = self . non_trivial_candidates ( goal) ;
444+ trace ! ( candidates = ?candidates. iter( ) . map( |c| c. kind( ) ) . collect:: <Vec <_>>( ) ) ;
445+
435446 let [ candidate] = candidates. as_slice ( ) else {
436447 return ControlFlow :: Break ( self . obligation . clone ( ) ) ;
437448 } ;
@@ -470,6 +481,8 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
470481
471482 let mut impl_where_bound_count = 0 ;
472483 for nested_goal in candidate. instantiate_nested_goals ( self . span ( ) ) {
484+ trace ! ( nested_goal = ?( nested_goal. goal( ) , nested_goal. source( ) , nested_goal. result( ) ) ) ;
485+
473486 let make_obligation = |cause| Obligation {
474487 cause,
475488 param_env : nested_goal. goal ( ) . param_env ,
@@ -496,7 +509,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
496509 ( _, GoalSource :: InstantiateHigherRanked ) => {
497510 obligation = self . obligation . clone ( ) ;
498511 }
499- ( ChildMode :: PassThrough , _) => {
512+ ( ChildMode :: PassThrough , _) | ( _ , GoalSource :: AliasWellFormed ) => {
500513 obligation = make_obligation ( self . obligation . cause . clone ( ) ) ;
501514 }
502515 }
0 commit comments