@@ -29,6 +29,7 @@ use ty::{self, TyCtxt};
29
29
use ty:: { ReEarlyBound , ReEmpty , ReErased , ReFree , ReStatic } ;
30
30
use ty:: { ReLateBound , ReScope , ReSkolemized , ReVar } ;
31
31
use ty:: { Region , RegionVid } ;
32
+ use ty:: fold:: TypeFoldable ;
32
33
33
34
mod graphviz;
34
35
@@ -110,11 +111,15 @@ struct LexicalResolver<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
110
111
}
111
112
112
113
impl < ' cx , ' gcx , ' tcx > LexicalResolver < ' cx , ' gcx , ' tcx > {
114
+ fn tcx ( & self ) -> TyCtxt < ' cx , ' gcx , ' tcx > {
115
+ self . region_rels . tcx
116
+ }
117
+
113
118
fn infer_variable_values (
114
119
& mut self ,
115
120
errors : & mut Vec < RegionResolutionError < ' tcx > > ,
116
121
) -> LexicalRegionResolutions < ' tcx > {
117
- let mut var_data = self . construct_var_data ( self . region_rels . tcx ) ;
122
+ let mut var_data = self . construct_var_data ( self . tcx ( ) ) ;
118
123
119
124
// Dorky hack to cause `dump_constraints` to only get called
120
125
// if debug mode is enabled:
@@ -255,7 +260,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
255
260
}
256
261
257
262
fn lub_concrete_regions ( & self , a : Region < ' tcx > , b : Region < ' tcx > ) -> Region < ' tcx > {
258
- let tcx = self . region_rels . tcx ;
263
+ let tcx = self . tcx ( ) ;
259
264
match ( a, b) {
260
265
( & ty:: ReCanonical ( ..) , _)
261
266
| ( _, & ty:: ReCanonical ( ..) )
@@ -296,10 +301,10 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
296
301
let fr_scope = match ( a, b) {
297
302
( & ReEarlyBound ( ref br) , _) | ( _, & ReEarlyBound ( ref br) ) => self . region_rels
298
303
. region_scope_tree
299
- . early_free_scope ( self . region_rels . tcx , br) ,
304
+ . early_free_scope ( self . tcx ( ) , br) ,
300
305
( & ReFree ( ref fr) , _) | ( _, & ReFree ( ref fr) ) => self . region_rels
301
306
. region_scope_tree
302
- . free_scope ( self . region_rels . tcx , fr) ,
307
+ . free_scope ( self . tcx ( ) , fr) ,
303
308
_ => bug ! ( ) ,
304
309
} ;
305
310
let r_id = self . region_rels
@@ -408,7 +413,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
408
413
409
414
for verify in & self . data . verifys {
410
415
debug ! ( "collect_errors: verify={:?}" , verify) ;
411
- let sub = var_data. normalize ( verify. region ) ;
416
+ let sub = var_data. normalize ( self . tcx ( ) , verify. region ) ;
412
417
413
418
// This was an inference variable which didn't get
414
419
// constrained, therefore it can be assume to hold.
@@ -712,11 +717,11 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
712
717
) -> bool {
713
718
match bound {
714
719
VerifyBound :: AnyRegion ( rs) => rs. iter ( )
715
- . map ( |& r| var_values. normalize ( r) )
720
+ . map ( |& r| var_values. normalize ( self . tcx ( ) , r) )
716
721
. any ( |r| self . region_rels . is_subregion_of ( min, r) ) ,
717
722
718
723
VerifyBound :: AllRegions ( rs) => rs. iter ( )
719
- . map ( |& r| var_values. normalize ( r) )
724
+ . map ( |& r| var_values. normalize ( self . tcx ( ) , r) )
720
725
. all ( |r| self . region_rels . is_subregion_of ( min, r) ) ,
721
726
722
727
VerifyBound :: AnyBound ( bs) => bs. iter ( ) . any ( |b| self . bound_is_met ( b, var_values, min) ) ,
@@ -733,11 +738,14 @@ impl<'tcx> fmt::Debug for RegionAndOrigin<'tcx> {
733
738
}
734
739
735
740
impl < ' tcx > LexicalRegionResolutions < ' tcx > {
736
- fn normalize ( & self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
737
- match * r {
738
- ty:: ReVar ( rid) => self . resolve_var ( rid) ,
741
+ fn normalize < T > ( & self , tcx : TyCtxt < ' _ , ' _ , ' tcx > , value : T ) -> T
742
+ where
743
+ T : TypeFoldable < ' tcx > ,
744
+ {
745
+ tcx. fold_regions ( & value, & mut false , |r, _db| match r {
746
+ ty:: ReVar ( rid) => self . resolve_var ( * rid) ,
739
747
_ => r,
740
- }
748
+ } )
741
749
}
742
750
743
751
fn value ( & self , rid : RegionVid ) -> & VarValue < ' tcx > {
0 commit comments