@@ -63,20 +63,6 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
63
63
mod candidate_assembly;
64
64
mod confirmation;
65
65
66
- /// Whether to consider the binder of higher ranked goals for the `leak_check` when
67
- /// evaluating higher-ranked goals. See #119820 for more info.
68
- ///
69
- /// While this is a bit hacky, it is necessary to match the behavior of the new solver:
70
- /// We eagerly instantiate binders in the new solver, outside of candidate selection, so
71
- /// the leak check inside of candidates does not consider any bound vars from the higher
72
- /// ranked goal. However, we do exit the binder once we're completely finished with a goal,
73
- /// so the leak-check can be used in evaluate by causing nested higher-ranked goals to fail.
74
- #[ derive( Debug , Copy , Clone ) ]
75
- enum LeakCheckHigherRankedGoal {
76
- No ,
77
- Yes ,
78
- }
79
-
80
66
#[ derive( Clone , Debug , Eq , PartialEq , Hash ) ]
81
67
pub enum IntercrateAmbiguityCause < ' tcx > {
82
68
DownstreamCrate { trait_ref : ty:: TraitRef < ' tcx > , self_ty : Option < Ty < ' tcx > > } ,
@@ -401,10 +387,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
401
387
let mut no_candidates_apply = true ;
402
388
403
389
for c in candidate_set. vec . iter ( ) {
404
- if self
405
- . evaluate_candidate ( stack, c, LeakCheckHigherRankedGoal :: No ) ?
406
- . may_apply ( )
407
- {
390
+ if self . evaluate_candidate ( stack, c) ?. may_apply ( ) {
408
391
no_candidates_apply = false ;
409
392
break ;
410
393
}
@@ -475,7 +458,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
475
458
// is needed for specialization. Propagate overflow if it occurs.
476
459
let mut candidates = candidates
477
460
. into_iter ( )
478
- . map ( |c| match self . evaluate_candidate ( stack, & c, LeakCheckHigherRankedGoal :: No ) {
461
+ . map ( |c| match self . evaluate_candidate ( stack, & c) {
479
462
Ok ( eval) if eval. may_apply ( ) => {
480
463
Ok ( Some ( EvaluatedCandidate { candidate : c, evaluation : eval } ) )
481
464
}
@@ -565,7 +548,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
565
548
obligation : & PredicateObligation < ' tcx > ,
566
549
) -> Result < EvaluationResult , OverflowError > {
567
550
debug_assert ! ( !self . infcx. next_trait_solver( ) ) ;
568
- self . evaluation_probe ( |this, _outer_universe | {
551
+ self . evaluation_probe ( |this| {
569
552
let goal =
570
553
this. infcx . resolve_vars_if_possible ( ( obligation. predicate , obligation. param_env ) ) ;
571
554
let mut result = this. evaluate_predicate_recursively (
@@ -588,11 +571,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
588
571
/// `op`, but this can be overwritten if necessary.
589
572
fn evaluation_probe (
590
573
& mut self ,
591
- op : impl FnOnce ( & mut Self , & mut ty :: UniverseIndex ) -> Result < EvaluationResult , OverflowError > ,
574
+ op : impl FnOnce ( & mut Self ) -> Result < EvaluationResult , OverflowError > ,
592
575
) -> Result < EvaluationResult , OverflowError > {
593
576
self . infcx . probe ( |snapshot| -> Result < EvaluationResult , OverflowError > {
594
- let mut outer_universe = self . infcx . universe ( ) ;
595
- let result = op ( self , & mut outer_universe ) ?;
577
+ let outer_universe = self . infcx . universe ( ) ;
578
+ let result = op ( self ) ?;
596
579
597
580
match self . infcx . leak_check ( outer_universe, Some ( snapshot) ) {
598
581
Ok ( ( ) ) => { }
@@ -1253,7 +1236,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1253
1236
}
1254
1237
1255
1238
match self . candidate_from_obligation ( stack) {
1256
- Ok ( Some ( c) ) => self . evaluate_candidate ( stack, & c, LeakCheckHigherRankedGoal :: Yes ) ,
1239
+ Ok ( Some ( c) ) => self . evaluate_candidate ( stack, & c) ,
1257
1240
Ok ( None ) => Ok ( EvaluatedToAmbig ) ,
1258
1241
Err ( Overflow ( OverflowError :: Canonical ) ) => Err ( OverflowError :: Canonical ) ,
1259
1242
Err ( ..) => Ok ( EvaluatedToErr ) ,
@@ -1278,10 +1261,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1278
1261
/// Further evaluates `candidate` to decide whether all type parameters match and whether nested
1279
1262
/// obligations are met. Returns whether `candidate` remains viable after this further
1280
1263
/// scrutiny.
1281
- ///
1282
- /// Depending on the value of [LeakCheckHigherRankedGoal], we may ignore the binder of the goal
1283
- /// when eagerly detecting higher ranked region errors via the `leak_check`. See that enum for
1284
- /// more info.
1285
1264
#[ instrument(
1286
1265
level = "debug" ,
1287
1266
skip( self , stack) ,
@@ -1292,25 +1271,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1292
1271
& mut self ,
1293
1272
stack : & TraitObligationStack < ' o , ' tcx > ,
1294
1273
candidate : & SelectionCandidate < ' tcx > ,
1295
- leak_check_higher_ranked_goal : LeakCheckHigherRankedGoal ,
1296
1274
) -> Result < EvaluationResult , OverflowError > {
1297
- let mut result = self . evaluation_probe ( |this, outer_universe| {
1298
- // We eagerly instantiate higher ranked goals to prevent universe errors
1299
- // from impacting candidate selection. This matches the behavior of the new
1300
- // solver. This slightly weakens type inference.
1301
- //
1302
- // In case there are no unresolved type or const variables this
1303
- // should still not be necessary to select a unique impl as any overlap
1304
- // relying on a universe error from higher ranked goals should have resulted
1305
- // in an overlap error in coherence.
1306
- let p = self . infcx . enter_forall_and_leak_universe ( stack. obligation . predicate ) ;
1307
- let obligation = stack. obligation . with ( this. tcx ( ) , ty:: Binder :: dummy ( p) ) ;
1308
- match leak_check_higher_ranked_goal {
1309
- LeakCheckHigherRankedGoal :: No => * outer_universe = self . infcx . universe ( ) ,
1310
- LeakCheckHigherRankedGoal :: Yes => { }
1311
- }
1312
-
1313
- match this. confirm_candidate ( & obligation, candidate. clone ( ) ) {
1275
+ let mut result = self . evaluation_probe ( |this| {
1276
+ match this. confirm_candidate ( stack. obligation , candidate. clone ( ) ) {
1314
1277
Ok ( selection) => {
1315
1278
debug ! ( ?selection) ;
1316
1279
this. evaluate_predicates_recursively (
@@ -1730,19 +1693,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1730
1693
} )
1731
1694
. map_err ( |_| ( ) )
1732
1695
}
1696
+
1733
1697
fn where_clause_may_apply < ' o > (
1734
1698
& mut self ,
1735
1699
stack : & TraitObligationStack < ' o , ' tcx > ,
1736
1700
where_clause_trait_ref : ty:: PolyTraitRef < ' tcx > ,
1737
1701
) -> Result < EvaluationResult , OverflowError > {
1738
- self . evaluation_probe ( |this, outer_universe| {
1739
- // Eagerly instantiate higher ranked goals.
1740
- //
1741
- // See the comment in `evaluate_candidate` to see why.
1742
- let p = self . infcx . enter_forall_and_leak_universe ( stack. obligation . predicate ) ;
1743
- let obligation = stack. obligation . with ( this. tcx ( ) , ty:: Binder :: dummy ( p) ) ;
1744
- * outer_universe = self . infcx . universe ( ) ;
1745
- match this. match_where_clause_trait_ref ( & obligation, where_clause_trait_ref) {
1702
+ self . evaluation_probe ( |this| {
1703
+ match this. match_where_clause_trait_ref ( stack. obligation , where_clause_trait_ref) {
1746
1704
Ok ( obligations) => this. evaluate_predicates_recursively ( stack. list ( ) , obligations) ,
1747
1705
Err ( ( ) ) => Ok ( EvaluatedToErr ) ,
1748
1706
}
0 commit comments