@@ -13,7 +13,7 @@ use rustc_middle::bug;
13
13
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
14
14
use rustc_middle:: ty:: { self , TyCtxt } ;
15
15
use rustc_next_trait_solver:: solve:: { GenerateProofTree , HasChanged , SolverDelegateEvalExt as _} ;
16
- use tracing:: instrument;
16
+ use tracing:: { instrument, trace } ;
17
17
18
18
use super :: Certainty ;
19
19
use super :: delegate:: SolverDelegate ;
@@ -402,6 +402,7 @@ impl<'tcx> BestObligation<'tcx> {
402
402
nested_goal. source( ) ,
403
403
GoalSource :: ImplWhereBound
404
404
| GoalSource :: InstantiateHigherRanked
405
+ | GoalSource :: AliasWellFormed
405
406
) && match self . consider_ambiguities {
406
407
true => {
407
408
matches ! (
@@ -416,6 +417,13 @@ impl<'tcx> BestObligation<'tcx> {
416
417
} )
417
418
} ) ;
418
419
}
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
+ }
419
427
}
420
428
}
421
429
@@ -430,8 +438,11 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
430
438
self . obligation . cause . span
431
439
}
432
440
441
+ #[ instrument( level = "trace" , skip( self , goal) , fields( goal = ?goal. goal( ) ) ) ]
433
442
fn visit_goal ( & mut self , goal : & inspect:: InspectGoal < ' _ , ' tcx > ) -> Self :: Result {
434
443
let candidates = self . non_trivial_candidates ( goal) ;
444
+ trace ! ( candidates = ?candidates. iter( ) . map( |c| c. kind( ) ) . collect:: <Vec <_>>( ) ) ;
445
+
435
446
let [ candidate] = candidates. as_slice ( ) else {
436
447
return ControlFlow :: Break ( self . obligation . clone ( ) ) ;
437
448
} ;
@@ -470,6 +481,8 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
470
481
471
482
let mut impl_where_bound_count = 0 ;
472
483
for nested_goal in candidate. instantiate_nested_goals ( self . span ( ) ) {
484
+ trace ! ( nested_goal = ?( nested_goal. goal( ) , nested_goal. source( ) , nested_goal. result( ) ) ) ;
485
+
473
486
let make_obligation = |cause| Obligation {
474
487
cause,
475
488
param_env : nested_goal. goal ( ) . param_env ,
@@ -496,7 +509,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
496
509
( _, GoalSource :: InstantiateHigherRanked ) => {
497
510
obligation = self . obligation . clone ( ) ;
498
511
}
499
- ( ChildMode :: PassThrough , _) => {
512
+ ( ChildMode :: PassThrough , _) | ( _ , GoalSource :: AliasWellFormed ) => {
500
513
obligation = make_obligation ( self . obligation . cause . clone ( ) ) ;
501
514
}
502
515
}
0 commit comments