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