10
10
11
11
use borrow_check:: nll:: constraints:: { ConstraintCategory , OutlivesConstraint } ;
12
12
use borrow_check:: nll:: type_check:: { BorrowCheckContext , Locations } ;
13
- use borrow_check:: nll:: universal_regions:: UniversalRegions ;
14
- use borrow_check:: nll:: ToRegionVid ;
15
13
use rustc:: infer:: canonical:: { Canonical , CanonicalVarInfos } ;
16
14
use rustc:: infer:: { InferCtxt , NLLRegionVariableOrigin } ;
17
15
use rustc:: traits:: query:: Fallible ;
18
16
use rustc:: ty:: fold:: { TypeFoldable , TypeVisitor } ;
19
17
use rustc:: ty:: relate:: { self , Relate , RelateResult , TypeRelation } ;
20
18
use rustc:: ty:: subst:: Kind ;
21
- use rustc:: ty:: { self , CanonicalTy , CanonicalVar , RegionVid , Ty , TyCtxt } ;
19
+ use rustc:: ty:: { self , CanonicalTy , CanonicalVar , Ty , TyCtxt } ;
22
20
use rustc_data_structures:: fx:: FxHashMap ;
23
21
use rustc_data_structures:: indexed_vec:: IndexVec ;
24
22
@@ -122,10 +120,10 @@ struct TypeRelating<'cx, 'bccx: 'cx, 'gcx: 'tcx, 'tcx: 'bccx> {
122
120
///
123
121
/// This field stores the instantiations for late-bound regions in
124
122
/// the `a` type.
125
- a_scopes : Vec < BoundRegionScope > ,
123
+ a_scopes : Vec < BoundRegionScope < ' tcx > > ,
126
124
127
125
/// Same as `a_scopes`, but for the `b` type.
128
- b_scopes : Vec < BoundRegionScope > ,
126
+ b_scopes : Vec < BoundRegionScope < ' tcx > > ,
129
127
130
128
/// Where (and why) is this relation taking place?
131
129
locations : Locations ,
@@ -152,13 +150,13 @@ struct TypeRelating<'cx, 'bccx: 'cx, 'gcx: 'tcx, 'tcx: 'bccx> {
152
150
153
151
#[ derive( Clone , Debug ) ]
154
152
struct ScopesAndKind < ' tcx > {
155
- scopes : Vec < BoundRegionScope > ,
153
+ scopes : Vec < BoundRegionScope < ' tcx > > ,
156
154
kind : Kind < ' tcx > ,
157
155
}
158
156
159
157
#[ derive( Clone , Debug , Default ) ]
160
- struct BoundRegionScope {
161
- map : FxHashMap < ty:: BoundRegion , RegionVid > ,
158
+ struct BoundRegionScope < ' tcx > {
159
+ map : FxHashMap < ty:: BoundRegion , ty :: Region < ' tcx > > ,
162
160
}
163
161
164
162
#[ derive( Copy , Clone ) ]
@@ -204,7 +202,7 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelating<'cx, 'bccx, 'gcx, 'tcx> {
204
202
& mut self ,
205
203
value : & ty:: Binder < impl TypeFoldable < ' tcx > > ,
206
204
universally_quantified : UniversallyQuantified ,
207
- ) -> BoundRegionScope {
205
+ ) -> BoundRegionScope < ' tcx > {
208
206
let mut scope = BoundRegionScope :: default ( ) ;
209
207
value. skip_binder ( ) . visit_with ( & mut ScopeInstantiator {
210
208
infcx : self . infcx ,
@@ -227,8 +225,8 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelating<'cx, 'bccx, 'gcx, 'tcx> {
227
225
debruijn : ty:: DebruijnIndex ,
228
226
br : & ty:: BoundRegion ,
229
227
first_free_index : ty:: DebruijnIndex ,
230
- scopes : & [ BoundRegionScope ] ,
231
- ) -> RegionVid {
228
+ scopes : & [ BoundRegionScope < ' tcx > ] ,
229
+ ) -> ty :: Region < ' tcx > {
232
230
// The debruijn index is a "reverse index" into the
233
231
// scopes listing. So when we have INNERMOST (0), we
234
232
// want the *last* scope pushed, and so forth.
@@ -245,28 +243,25 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelating<'cx, 'bccx, 'gcx, 'tcx> {
245
243
/// with. Otherwise just return `r`.
246
244
fn replace_bound_region (
247
245
& self ,
248
- universal_regions : & UniversalRegions < ' tcx > ,
249
246
r : ty:: Region < ' tcx > ,
250
247
first_free_index : ty:: DebruijnIndex ,
251
- scopes : & [ BoundRegionScope ] ,
252
- ) -> RegionVid {
253
- match r {
254
- ty:: ReLateBound ( debruijn, br) => {
255
- Self :: lookup_bound_region ( * debruijn, br, first_free_index, scopes)
256
- }
257
-
258
- ty:: ReVar ( v) => * v,
259
-
260
- _ => universal_regions. to_region_vid ( r) ,
248
+ scopes : & [ BoundRegionScope < ' tcx > ] ,
249
+ ) -> ty:: Region < ' tcx > {
250
+ if let ty:: ReLateBound ( debruijn, br) = r {
251
+ Self :: lookup_bound_region ( * debruijn, br, first_free_index, scopes)
252
+ } else {
253
+ r
261
254
}
262
255
}
263
256
264
257
/// Push a new outlives requirement into our output set of
265
258
/// constraints.
266
- fn push_outlives ( & mut self , sup : RegionVid , sub : RegionVid ) {
259
+ fn push_outlives ( & mut self , sup : ty :: Region < ' tcx > , sub : ty :: Region < ' tcx > ) {
267
260
debug ! ( "push_outlives({:?}: {:?})" , sup, sub) ;
268
261
269
262
if let Some ( borrowck_context) = & mut self . borrowck_context {
263
+ let sub = borrowck_context. universal_regions . to_region_vid ( sub) ;
264
+ let sup = borrowck_context. universal_regions . to_region_vid ( sup) ;
270
265
borrowck_context
271
266
. constraints
272
267
. outlives_constraints
@@ -316,10 +311,7 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelating<'cx, 'bccx, 'gcx, 'tcx> {
316
311
return result;
317
312
}
318
313
319
- fn generalize_value (
320
- & self ,
321
- kind : Kind < ' tcx > ,
322
- ) -> Kind < ' tcx > {
314
+ fn generalize_value ( & self , kind : Kind < ' tcx > ) -> Kind < ' tcx > {
323
315
TypeGeneralizer {
324
316
type_rel : self ,
325
317
first_free_index : ty:: INNERMOST ,
@@ -397,37 +389,30 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx>
397
389
a : ty:: Region < ' tcx > ,
398
390
b : ty:: Region < ' tcx > ,
399
391
) -> RelateResult < ' tcx , ty:: Region < ' tcx > > {
400
- if let Some ( & mut BorrowCheckContext {
401
- universal_regions, ..
402
- } ) = self . borrowck_context
403
- {
404
- if let ty:: ReCanonical ( var) = a {
405
- self . relate_var ( * var, b. into ( ) ) ?;
406
- return Ok ( a) ;
407
- }
392
+ if let ty:: ReCanonical ( var) = a {
393
+ self . relate_var ( * var, b. into ( ) ) ?;
394
+ return Ok ( a) ;
395
+ }
408
396
409
- debug ! (
410
- "regions(a={:?}, b={:?}, variance={:?})" ,
411
- a, b, self . ambient_variance
412
- ) ;
397
+ debug ! (
398
+ "regions(a={:?}, b={:?}, variance={:?})" ,
399
+ a, b, self . ambient_variance
400
+ ) ;
413
401
414
- let v_a =
415
- self . replace_bound_region ( universal_regions, a, ty:: INNERMOST , & self . a_scopes ) ;
416
- let v_b =
417
- self . replace_bound_region ( universal_regions, b, ty:: INNERMOST , & self . b_scopes ) ;
402
+ let v_a = self . replace_bound_region ( a, ty:: INNERMOST , & self . a_scopes ) ;
403
+ let v_b = self . replace_bound_region ( b, ty:: INNERMOST , & self . b_scopes ) ;
418
404
419
- debug ! ( "regions: v_a = {:?}" , v_a) ;
420
- debug ! ( "regions: v_b = {:?}" , v_b) ;
405
+ debug ! ( "regions: v_a = {:?}" , v_a) ;
406
+ debug ! ( "regions: v_b = {:?}" , v_b) ;
421
407
422
- if self . ambient_covariance ( ) {
423
- // Covariance: a <= b. Hence, `b: a`.
424
- self . push_outlives ( v_b, v_a) ;
425
- }
408
+ if self . ambient_covariance ( ) {
409
+ // Covariance: a <= b. Hence, `b: a`.
410
+ self . push_outlives ( v_b, v_a) ;
411
+ }
426
412
427
- if self . ambient_contravariance ( ) {
428
- // Contravariant: b <= a. Hence, `a: b`.
429
- self . push_outlives ( v_a, v_b) ;
430
- }
413
+ if self . ambient_contravariance ( ) {
414
+ // Contravariant: b <= a. Hence, `a: b`.
415
+ self . push_outlives ( v_a, v_b) ;
431
416
}
432
417
433
418
Ok ( a)
@@ -527,10 +512,8 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx>
527
512
528
513
// Reset ambient variance to contravariance. See the
529
514
// covariant case above for an explanation.
530
- let variance = :: std:: mem:: replace (
531
- & mut self . ambient_variance ,
532
- ty:: Variance :: Contravariant ,
533
- ) ;
515
+ let variance =
516
+ :: std:: mem:: replace ( & mut self . ambient_variance , ty:: Variance :: Contravariant ) ;
534
517
535
518
self . relate ( a. skip_binder ( ) , b. skip_binder ( ) ) ?;
536
519
@@ -556,7 +539,7 @@ struct ScopeInstantiator<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
556
539
// The debruijn index of the scope we are instantiating.
557
540
target_index : ty:: DebruijnIndex ,
558
541
universally_quantified : UniversallyQuantified ,
559
- bound_region_scope : & ' cx mut BoundRegionScope ,
542
+ bound_region_scope : & ' cx mut BoundRegionScope < ' tcx > ,
560
543
}
561
544
562
545
impl < ' cx , ' gcx , ' tcx > TypeVisitor < ' tcx > for ScopeInstantiator < ' cx , ' gcx , ' tcx > {
@@ -583,7 +566,7 @@ impl<'cx, 'gcx, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'cx, 'gcx, 'tcx> {
583
566
} else {
584
567
NLLRegionVariableOrigin :: Existential
585
568
} ;
586
- infcx. next_nll_region_var ( origin) . to_region_vid ( )
569
+ infcx. next_nll_region_var ( origin)
587
570
} ) ;
588
571
}
589
572
0 commit comments