@@ -31,14 +31,6 @@ pub trait HigherRankedRelations<'a,'tcx> {
31
31
where T : Relate < ' a , ' tcx > ;
32
32
}
33
33
34
- trait InferCtxtExt {
35
- fn tainted_regions ( & self , snapshot : & CombinedSnapshot , r : ty:: Region ) -> Vec < ty:: Region > ;
36
-
37
- fn region_vars_confined_to_snapshot ( & self ,
38
- snapshot : & CombinedSnapshot )
39
- -> Vec < ty:: RegionVid > ;
40
- }
41
-
42
34
impl < ' a , ' tcx > HigherRankedRelations < ' a , ' tcx > for CombineFields < ' a , ' tcx > {
43
35
fn higher_ranked_sub < T > ( & self , a : & Binder < T > , b : & Binder < T > )
44
36
-> RelateResult < ' tcx , Binder < T > >
@@ -79,23 +71,9 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a,'tcx> {
79
71
80
72
// Presuming type comparison succeeds, we need to check
81
73
// that the skolemized regions do not "leak".
82
- match leak_check ( self . infcx , & skol_map, snapshot) {
83
- Ok ( ( ) ) => { }
84
- Err ( ( skol_br, tainted_region) ) => {
85
- if self . a_is_expected {
86
- debug ! ( "Not as polymorphic!" ) ;
87
- return Err ( TypeError :: RegionsInsufficientlyPolymorphic ( skol_br,
88
- tainted_region) ) ;
89
- } else {
90
- debug ! ( "Overly polymorphic!" ) ;
91
- return Err ( TypeError :: RegionsOverlyPolymorphic ( skol_br,
92
- tainted_region) ) ;
93
- }
94
- }
95
- }
74
+ self . infcx . leak_check ( !self . a_is_expected , & skol_map, snapshot) ?;
96
75
97
- debug ! ( "higher_ranked_sub: OK result={:?}" ,
98
- result) ;
76
+ debug ! ( "higher_ranked_sub: OK result={:?}" , result) ;
99
77
100
78
Ok ( ty:: Binder ( result) )
101
79
} ) ;
@@ -371,7 +349,7 @@ fn fold_regions_in<'tcx, T, F>(tcx: &TyCtxt<'tcx>,
371
349
} )
372
350
}
373
351
374
- impl < ' a , ' tcx > InferCtxtExt for InferCtxt < ' a , ' tcx > {
352
+ impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
375
353
fn tainted_regions ( & self , snapshot : & CombinedSnapshot , r : ty:: Region ) -> Vec < ty:: Region > {
376
354
self . region_vars . tainted ( & snapshot. region_vars_snapshot , r)
377
355
}
@@ -452,12 +430,11 @@ impl<'a,'tcx> InferCtxtExt for InferCtxt<'a,'tcx> {
452
430
453
431
region_vars
454
432
}
455
- }
456
433
457
- pub fn skolemize_late_bound_regions < ' a , ' tcx , T > ( infcx : & InferCtxt < ' a , ' tcx > ,
458
- binder : & ty:: Binder < T > ,
459
- snapshot : & CombinedSnapshot )
460
- -> ( T , SkolemizationMap )
434
+ pub fn skolemize_late_bound_regions < T > ( & self ,
435
+ binder : & ty:: Binder < T > ,
436
+ snapshot : & CombinedSnapshot )
437
+ -> ( T , SkolemizationMap )
461
438
where T : TypeFoldable < ' tcx >
462
439
{
463
440
/*!
@@ -468,8 +445,8 @@ pub fn skolemize_late_bound_regions<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
468
445
* details.
469
446
*/
470
447
471
- let ( result, map) = infcx . tcx . replace_late_bound_regions ( binder, |br| {
472
- infcx . region_vars . new_skolemized ( br, & snapshot. region_vars_snapshot )
448
+ let ( result, map) = self . tcx . replace_late_bound_regions ( binder, |br| {
449
+ self . region_vars . new_skolemized ( br, & snapshot. region_vars_snapshot )
473
450
} ) ;
474
451
475
452
debug ! ( "skolemize_bound_regions(binder={:?}, result={:?}, map={:?})" ,
@@ -480,10 +457,11 @@ pub fn skolemize_late_bound_regions<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
480
457
( result, map)
481
458
}
482
459
483
- pub fn leak_check < ' a , ' tcx > ( infcx : & InferCtxt < ' a , ' tcx > ,
484
- skol_map : & SkolemizationMap ,
485
- snapshot : & CombinedSnapshot )
486
- -> Result < ( ) , ( ty:: BoundRegion , ty:: Region ) >
460
+ pub fn leak_check ( & self ,
461
+ overly_polymorphic : bool ,
462
+ skol_map : & SkolemizationMap ,
463
+ snapshot : & CombinedSnapshot )
464
+ -> RelateResult < ' tcx , ( ) >
487
465
{
488
466
/*!
489
467
* Searches the region constriants created since `snapshot` was started
@@ -496,9 +474,9 @@ pub fn leak_check<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
496
474
debug ! ( "leak_check: skol_map={:?}" ,
497
475
skol_map) ;
498
476
499
- let new_vars = infcx . region_vars_confined_to_snapshot ( snapshot) ;
477
+ let new_vars = self . region_vars_confined_to_snapshot ( snapshot) ;
500
478
for ( & skol_br, & skol) in skol_map {
501
- let tainted = infcx . tainted_regions ( snapshot, skol) ;
479
+ let tainted = self . tainted_regions ( snapshot, skol) ;
502
480
for & tainted_region in & tainted {
503
481
// Each skolemized should only be relatable to itself
504
482
// or new variables:
@@ -516,8 +494,15 @@ pub fn leak_check<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
516
494
skol_br,
517
495
tainted_region) ;
518
496
519
- // A is not as polymorphic as B:
520
- return Err ( ( skol_br, tainted_region) ) ;
497
+ if overly_polymorphic {
498
+ debug ! ( "Overly polymorphic!" ) ;
499
+ return Err ( TypeError :: RegionsOverlyPolymorphic ( skol_br,
500
+ tainted_region) ) ;
501
+ } else {
502
+ debug ! ( "Not as polymorphic!" ) ;
503
+ return Err ( TypeError :: RegionsInsufficientlyPolymorphic ( skol_br,
504
+ tainted_region) ) ;
505
+ }
521
506
}
522
507
}
523
508
Ok ( ( ) )
@@ -551,14 +536,13 @@ pub fn leak_check<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
551
536
/// replace `'0` with a late-bound region `'a`. The depth is matched
552
537
/// to the depth of the predicate, in this case 1, so that the final
553
538
/// predicate is `for<'a> &'a int : Clone`.
554
- pub fn plug_leaks < ' a , ' tcx , T > ( infcx : & InferCtxt < ' a , ' tcx > ,
555
- skol_map : SkolemizationMap ,
556
- snapshot : & CombinedSnapshot ,
557
- value : & T )
558
- -> T
539
+ pub fn plug_leaks < T > ( & self ,
540
+ skol_map : SkolemizationMap ,
541
+ snapshot : & CombinedSnapshot ,
542
+ value : & T ) -> T
559
543
where T : TypeFoldable < ' tcx >
560
544
{
561
- debug_assert ! ( leak_check( infcx , & skol_map, snapshot) . is_ok( ) ) ;
545
+ debug_assert ! ( self . leak_check( false , & skol_map, snapshot) . is_ok( ) ) ;
562
546
563
547
debug ! ( "plug_leaks(skol_map={:?}, value={:?})" ,
564
548
skol_map,
@@ -572,7 +556,7 @@ pub fn plug_leaks<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
572
556
skol_map
573
557
. into_iter ( )
574
558
. flat_map ( |( skol_br, skol) | {
575
- infcx . tainted_regions ( snapshot, skol)
559
+ self . tainted_regions ( snapshot, skol)
576
560
. into_iter ( )
577
561
. map ( move |tainted_region| ( tainted_region, skol_br) )
578
562
} )
@@ -583,14 +567,14 @@ pub fn plug_leaks<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
583
567
584
568
// Remove any instantiated type variables from `value`; those can hide
585
569
// references to regions from the `fold_regions` code below.
586
- let value = infcx . resolve_type_vars_if_possible ( value) ;
570
+ let value = self . resolve_type_vars_if_possible ( value) ;
587
571
588
572
// Map any skolemization byproducts back to a late-bound
589
573
// region. Put that late-bound region at whatever the outermost
590
574
// binder is that we encountered in `value`. The caller is
591
575
// responsible for ensuring that (a) `value` contains at least one
592
576
// binder and (b) that binder is the one we want to use.
593
- let result = infcx . tcx . fold_regions ( & value, & mut false , |r, current_depth| {
577
+ let result = self . tcx . fold_regions ( & value, & mut false , |r, current_depth| {
594
578
match inv_skol_map. get ( & r) {
595
579
None => r,
596
580
Some ( br) => {
@@ -612,3 +596,4 @@ pub fn plug_leaks<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
612
596
613
597
result
614
598
}
599
+ }
0 commit comments