@@ -38,14 +38,13 @@ pub enum NormalizationStrategy {
38
38
Eager ,
39
39
}
40
40
41
- pub struct TypeRelating < ' me , ' tcx , D >
41
+ pub struct TypeRelating < ' cx , ' tcx , D >
42
42
where
43
- D : TypeRelatingDelegate < ' tcx > ,
43
+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
44
44
{
45
- infcx : & ' me InferCtxt < ' me , ' tcx > ,
46
-
47
45
/// Callback to use when we deduce an outlives relationship
48
46
delegate : D ,
47
+ _infcx : std:: marker:: PhantomData < & ' cx mut InferCtxt < ' cx , ' tcx > > ,
49
48
50
49
/// How are we relating `a` and `b`?
51
50
///
71
70
b_scopes : Vec < BoundRegionScope < ' tcx > > ,
72
71
}
73
72
74
- pub trait TypeRelatingDelegate < ' tcx > {
73
+ pub trait TypeRelatingDelegate < ' cx , ' tcx > {
74
+ fn infcx ( & self ) -> & mut InferCtxt < ' cx , ' tcx > ;
75
+
75
76
/// Push a constraint `sup: sub` -- this constraint must be
76
77
/// satisfied for the two types to be related. `sub` and `sup` may
77
78
/// be regions from the type or new variables created through the
@@ -127,16 +128,15 @@ struct BoundRegionScope<'tcx> {
127
128
#[ derive( Copy , Clone ) ]
128
129
struct UniversallyQuantified ( bool ) ;
129
130
130
- impl < ' me , ' tcx , D > TypeRelating < ' me , ' tcx , D >
131
+ impl < D > TypeRelating < ' cx , ' tcx , D >
131
132
where
132
- D : TypeRelatingDelegate < ' tcx > ,
133
+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
133
134
{
134
135
pub fn new (
135
- infcx : & ' me InferCtxt < ' me , ' tcx > ,
136
136
delegate : D ,
137
137
ambient_variance : ty:: Variance ,
138
138
) -> Self {
139
- Self { infcx , delegate, ambient_variance, a_scopes : vec ! [ ] , b_scopes : vec ! [ ] }
139
+ Self { _infcx : std :: marker :: PhantomData , delegate, ambient_variance, a_scopes : vec ! [ ] , b_scopes : vec ! [ ] }
140
140
}
141
141
142
142
fn ambient_covariance ( & self ) -> bool {
@@ -261,7 +261,7 @@ where
261
261
262
262
match * value_ty. kind ( ) {
263
263
ty:: Projection ( other_projection_ty) => {
264
- let var = self . infcx . next_ty_var ( TypeVariableOrigin {
264
+ let var = self . delegate . infcx ( ) . next_ty_var ( TypeVariableOrigin {
265
265
kind : TypeVariableOriginKind :: MiscVariable ,
266
266
span : DUMMY_SP ,
267
267
} ) ;
@@ -308,12 +308,12 @@ where
308
308
match * value_ty. kind ( ) {
309
309
ty:: Infer ( ty:: TyVar ( value_vid) ) => {
310
310
// Two type variables: just equate them.
311
- self . infcx . inner . type_variables ( ) . equate ( vid, value_vid) ;
311
+ self . delegate . infcx ( ) . inner . type_variables ( ) . equate ( vid, value_vid) ;
312
312
return Ok ( value_ty) ;
313
313
}
314
314
315
315
ty:: Projection ( projection_ty) if D :: normalization ( ) == NormalizationStrategy :: Lazy => {
316
- return Ok ( self . relate_projection_ty ( projection_ty, self . infcx . tcx . mk_ty_var ( vid) ) ) ;
316
+ return Ok ( self . relate_projection_ty ( projection_ty, self . delegate . infcx ( ) . tcx . mk_ty_var ( vid) ) ) ;
317
317
}
318
318
319
319
_ => ( ) ,
@@ -329,7 +329,7 @@ where
329
329
assert ! ( !generalized_ty. has_infer_types_or_consts( ) ) ;
330
330
}
331
331
332
- self . infcx . inner . type_variables ( ) . instantiate ( vid, generalized_ty) ;
332
+ self . delegate . infcx ( ) . inner . type_variables ( ) . instantiate ( vid, generalized_ty) ;
333
333
334
334
// The generalized values we extract from `canonical_var_values` have
335
335
// been fully instantiated and hence the set of scopes we have
@@ -352,14 +352,14 @@ where
352
352
value : T ,
353
353
for_vid : ty:: TyVid ,
354
354
) -> RelateResult < ' tcx , T > {
355
- let universe = self . infcx . probe_ty_var ( for_vid) . unwrap_err ( ) ;
355
+ let universe = self . delegate . infcx ( ) . probe_ty_var ( for_vid) . unwrap_err ( ) ;
356
356
357
357
let mut generalizer = TypeGeneralizer {
358
- infcx : self . infcx ,
358
+ infcx : self . delegate . infcx ( ) ,
359
359
delegate : & mut self . delegate ,
360
360
first_free_index : ty:: INNERMOST ,
361
361
ambient_variance : self . ambient_variance ,
362
- for_vid_sub_root : self . infcx . inner . type_variables ( ) . sub_root_var ( for_vid) ,
362
+ for_vid_sub_root : self . delegate . infcx ( ) . inner . type_variables ( ) . sub_root_var ( for_vid) ,
363
363
universe,
364
364
} ;
365
365
@@ -385,21 +385,21 @@ trait VidValuePair<'tcx>: Debug {
385
385
/// Extract the scopes that apply to whichever side of the tuple
386
386
/// the vid was found on. See the comment where this is called
387
387
/// for more details on why we want them.
388
- fn vid_scopes < D : TypeRelatingDelegate < ' tcx > > (
388
+ fn vid_scopes < D : TypeRelatingDelegate < ' cx , ' tcx > > (
389
389
& self ,
390
- relate : & ' r mut TypeRelating < ' _ , ' tcx , D > ,
390
+ relate : & ' r mut TypeRelating < ' cx , ' tcx , D > ,
391
391
) -> & ' r mut Vec < BoundRegionScope < ' tcx > > ;
392
392
393
393
/// Given a generalized type G that should replace the vid, relate
394
394
/// G to the value, putting G on whichever side the vid would have
395
395
/// appeared.
396
396
fn relate_generalized_ty < D > (
397
397
& self ,
398
- relate : & mut TypeRelating < ' _ , ' tcx , D > ,
398
+ relate : & mut TypeRelating < ' cx , ' tcx , D > ,
399
399
generalized_ty : Ty < ' tcx > ,
400
400
) -> RelateResult < ' tcx , Ty < ' tcx > >
401
401
where
402
- D : TypeRelatingDelegate < ' tcx > ;
402
+ D : TypeRelatingDelegate < ' cx , ' tcx > ;
403
403
}
404
404
405
405
impl VidValuePair < ' tcx > for ( ty:: TyVid , Ty < ' tcx > ) {
@@ -413,21 +413,21 @@ impl VidValuePair<'tcx> for (ty::TyVid, Ty<'tcx>) {
413
413
414
414
fn vid_scopes < D > (
415
415
& self ,
416
- relate : & ' r mut TypeRelating < ' _ , ' tcx , D > ,
416
+ relate : & ' r mut TypeRelating < ' cx , ' tcx , D > ,
417
417
) -> & ' r mut Vec < BoundRegionScope < ' tcx > >
418
418
where
419
- D : TypeRelatingDelegate < ' tcx > ,
419
+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
420
420
{
421
421
& mut relate. a_scopes
422
422
}
423
423
424
424
fn relate_generalized_ty < D > (
425
425
& self ,
426
- relate : & mut TypeRelating < ' _ , ' tcx , D > ,
426
+ relate : & mut TypeRelating < ' cx , ' tcx , D > ,
427
427
generalized_ty : Ty < ' tcx > ,
428
428
) -> RelateResult < ' tcx , Ty < ' tcx > >
429
429
where
430
- D : TypeRelatingDelegate < ' tcx > ,
430
+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
431
431
{
432
432
relate. relate ( & generalized_ty, & self . value_ty ( ) )
433
433
}
@@ -445,32 +445,32 @@ impl VidValuePair<'tcx> for (Ty<'tcx>, ty::TyVid) {
445
445
446
446
fn vid_scopes < D > (
447
447
& self ,
448
- relate : & ' r mut TypeRelating < ' _ , ' tcx , D > ,
448
+ relate : & ' r mut TypeRelating < ' cx , ' tcx , D > ,
449
449
) -> & ' r mut Vec < BoundRegionScope < ' tcx > >
450
450
where
451
- D : TypeRelatingDelegate < ' tcx > ,
451
+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
452
452
{
453
453
& mut relate. b_scopes
454
454
}
455
455
456
456
fn relate_generalized_ty < D > (
457
457
& self ,
458
- relate : & mut TypeRelating < ' _ , ' tcx , D > ,
458
+ relate : & mut TypeRelating < ' cx , ' tcx , D > ,
459
459
generalized_ty : Ty < ' tcx > ,
460
460
) -> RelateResult < ' tcx , Ty < ' tcx > >
461
461
where
462
- D : TypeRelatingDelegate < ' tcx > ,
462
+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
463
463
{
464
464
relate. relate ( & self . value_ty ( ) , & generalized_ty)
465
465
}
466
466
}
467
467
468
- impl < D > TypeRelation < ' tcx > for TypeRelating < ' me , ' tcx , D >
468
+ impl < D > TypeRelation < ' tcx > for TypeRelating < ' cx , ' tcx , D >
469
469
where
470
- D : TypeRelatingDelegate < ' tcx > ,
470
+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
471
471
{
472
472
fn tcx ( & self ) -> TyCtxt < ' tcx > {
473
- self . infcx . tcx
473
+ self . delegate . infcx ( ) . tcx
474
474
}
475
475
476
476
// FIXME(oli-obk): not sure how to get the correct ParamEnv
@@ -509,10 +509,10 @@ where
509
509
}
510
510
511
511
fn tys ( & mut self , a : Ty < ' tcx > , mut b : Ty < ' tcx > ) -> RelateResult < ' tcx , Ty < ' tcx > > {
512
- let a = self . infcx . shallow_resolve ( a) ;
512
+ let a = self . delegate . infcx ( ) . shallow_resolve ( a) ;
513
513
514
514
if !D :: forbid_inference_vars ( ) {
515
- b = self . infcx . shallow_resolve ( b) ;
515
+ b = self . delegate . infcx ( ) . shallow_resolve ( b) ;
516
516
}
517
517
518
518
if a == b {
@@ -553,7 +553,7 @@ where
553
553
debug ! ( "tys(a={:?}, b={:?}, variance={:?})" , a, b, self . ambient_variance) ;
554
554
555
555
// Will also handle unification of `IntVar` and `FloatVar`.
556
- self . infcx . super_combine_tys ( self , a, b)
556
+ self . delegate . infcx ( ) . super_combine_tys ( self , a, b)
557
557
}
558
558
}
559
559
}
@@ -589,10 +589,10 @@ where
589
589
a : & ' tcx ty:: Const < ' tcx > ,
590
590
mut b : & ' tcx ty:: Const < ' tcx > ,
591
591
) -> RelateResult < ' tcx , & ' tcx ty:: Const < ' tcx > > {
592
- let a = self . infcx . shallow_resolve ( a) ;
592
+ let a = self . delegate . infcx ( ) . shallow_resolve ( a) ;
593
593
594
594
if !D :: forbid_inference_vars ( ) {
595
- b = self . infcx . shallow_resolve ( b) ;
595
+ b = self . delegate . infcx ( ) . shallow_resolve ( b) ;
596
596
}
597
597
598
598
match b. val {
@@ -601,7 +601,7 @@ where
601
601
bug ! ( "unexpected inference var {:?}" , b)
602
602
}
603
603
// FIXME(invariance): see the related FIXME above.
604
- _ => self . infcx . super_combine_consts ( self , a, b) ,
604
+ _ => self . delegate . infcx ( ) . super_combine_consts ( self , a, b) ,
605
605
}
606
606
}
607
607
@@ -717,9 +717,9 @@ where
717
717
}
718
718
}
719
719
720
- impl < ' tcx , D > ConstEquateRelation < ' tcx > for TypeRelating < ' _ , ' tcx , D >
720
+ impl < D > ConstEquateRelation < ' tcx > for TypeRelating < ' cx , ' tcx , D >
721
721
where
722
- D : TypeRelatingDelegate < ' tcx > ,
722
+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
723
723
{
724
724
fn const_equate_obligation ( & mut self , a : & ' tcx ty:: Const < ' tcx > , b : & ' tcx ty:: Const < ' tcx > ) {
725
725
self . delegate . const_equate ( a, b) ;
@@ -788,7 +788,7 @@ impl<'me, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'me, 'tcx> {
788
788
/// [blog post]: https://is.gd/0hKvIr
789
789
struct TypeGeneralizer < ' me , ' tcx , D >
790
790
where
791
- D : TypeRelatingDelegate < ' tcx > ,
791
+ D : TypeRelatingDelegate < ' me , ' tcx > ,
792
792
{
793
793
infcx : & ' me InferCtxt < ' me , ' tcx > ,
794
794
@@ -813,10 +813,10 @@ where
813
813
814
814
impl < D > TypeRelation < ' tcx > for TypeGeneralizer < ' me , ' tcx , D >
815
815
where
816
- D : TypeRelatingDelegate < ' tcx > ,
816
+ D : TypeRelatingDelegate < ' me , ' tcx > ,
817
817
{
818
818
fn tcx ( & self ) -> TyCtxt < ' tcx > {
819
- self . infcx . tcx
819
+ self . delegate . infcx ( ) . tcx
820
820
}
821
821
822
822
// FIXME(oli-obk): not sure how to get the correct ParamEnv
0 commit comments