@@ -38,14 +38,13 @@ pub enum NormalizationStrategy {
3838 Eager ,
3939}
4040
41- pub struct TypeRelating < ' me , ' tcx , D >
41+ pub struct TypeRelating < ' cx , ' tcx , D >
4242where
43- D : TypeRelatingDelegate < ' tcx > ,
43+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
4444{
45- infcx : & ' me InferCtxt < ' me , ' tcx > ,
46-
4745 /// Callback to use when we deduce an outlives relationship
4846 delegate : D ,
47+ _infcx : std:: marker:: PhantomData < & ' cx mut InferCtxt < ' cx , ' tcx > > ,
4948
5049 /// How are we relating `a` and `b`?
5150 ///
7170 b_scopes : Vec < BoundRegionScope < ' tcx > > ,
7271}
7372
74- pub trait TypeRelatingDelegate < ' tcx > {
73+ pub trait TypeRelatingDelegate < ' cx , ' tcx > {
74+ fn infcx ( & self ) -> & mut InferCtxt < ' cx , ' tcx > ;
75+
7576 /// Push a constraint `sup: sub` -- this constraint must be
7677 /// satisfied for the two types to be related. `sub` and `sup` may
7778 /// be regions from the type or new variables created through the
@@ -127,16 +128,15 @@ struct BoundRegionScope<'tcx> {
127128#[ derive( Copy , Clone ) ]
128129struct UniversallyQuantified ( bool ) ;
129130
130- impl < ' me , ' tcx , D > TypeRelating < ' me , ' tcx , D >
131+ impl < D > TypeRelating < ' cx , ' tcx , D >
131132where
132- D : TypeRelatingDelegate < ' tcx > ,
133+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
133134{
134135 pub fn new (
135- infcx : & ' me InferCtxt < ' me , ' tcx > ,
136136 delegate : D ,
137137 ambient_variance : ty:: Variance ,
138138 ) -> 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 ! [ ] }
140140 }
141141
142142 fn ambient_covariance ( & self ) -> bool {
@@ -261,7 +261,7 @@ where
261261
262262 match * value_ty. kind ( ) {
263263 ty:: Projection ( other_projection_ty) => {
264- let var = self . infcx . next_ty_var ( TypeVariableOrigin {
264+ let var = self . delegate . infcx ( ) . next_ty_var ( TypeVariableOrigin {
265265 kind : TypeVariableOriginKind :: MiscVariable ,
266266 span : DUMMY_SP ,
267267 } ) ;
@@ -308,12 +308,12 @@ where
308308 match * value_ty. kind ( ) {
309309 ty:: Infer ( ty:: TyVar ( value_vid) ) => {
310310 // 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) ;
312312 return Ok ( value_ty) ;
313313 }
314314
315315 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) ) ) ;
317317 }
318318
319319 _ => ( ) ,
@@ -329,7 +329,7 @@ where
329329 assert ! ( !generalized_ty. has_infer_types_or_consts( ) ) ;
330330 }
331331
332- self . infcx . inner . type_variables ( ) . instantiate ( vid, generalized_ty) ;
332+ self . delegate . infcx ( ) . inner . type_variables ( ) . instantiate ( vid, generalized_ty) ;
333333
334334 // The generalized values we extract from `canonical_var_values` have
335335 // been fully instantiated and hence the set of scopes we have
@@ -352,14 +352,14 @@ where
352352 value : T ,
353353 for_vid : ty:: TyVid ,
354354 ) -> 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 ( ) ;
356356
357357 let mut generalizer = TypeGeneralizer {
358- infcx : self . infcx ,
358+ infcx : self . delegate . infcx ( ) ,
359359 delegate : & mut self . delegate ,
360360 first_free_index : ty:: INNERMOST ,
361361 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) ,
363363 universe,
364364 } ;
365365
@@ -385,21 +385,21 @@ trait VidValuePair<'tcx>: Debug {
385385 /// Extract the scopes that apply to whichever side of the tuple
386386 /// the vid was found on. See the comment where this is called
387387 /// for more details on why we want them.
388- fn vid_scopes < D : TypeRelatingDelegate < ' tcx > > (
388+ fn vid_scopes < D : TypeRelatingDelegate < ' cx , ' tcx > > (
389389 & self ,
390- relate : & ' r mut TypeRelating < ' _ , ' tcx , D > ,
390+ relate : & ' r mut TypeRelating < ' cx , ' tcx , D > ,
391391 ) -> & ' r mut Vec < BoundRegionScope < ' tcx > > ;
392392
393393 /// Given a generalized type G that should replace the vid, relate
394394 /// G to the value, putting G on whichever side the vid would have
395395 /// appeared.
396396 fn relate_generalized_ty < D > (
397397 & self ,
398- relate : & mut TypeRelating < ' _ , ' tcx , D > ,
398+ relate : & mut TypeRelating < ' cx , ' tcx , D > ,
399399 generalized_ty : Ty < ' tcx > ,
400400 ) -> RelateResult < ' tcx , Ty < ' tcx > >
401401 where
402- D : TypeRelatingDelegate < ' tcx > ;
402+ D : TypeRelatingDelegate < ' cx , ' tcx > ;
403403}
404404
405405impl VidValuePair < ' tcx > for ( ty:: TyVid , Ty < ' tcx > ) {
@@ -413,21 +413,21 @@ impl VidValuePair<'tcx> for (ty::TyVid, Ty<'tcx>) {
413413
414414 fn vid_scopes < D > (
415415 & self ,
416- relate : & ' r mut TypeRelating < ' _ , ' tcx , D > ,
416+ relate : & ' r mut TypeRelating < ' cx , ' tcx , D > ,
417417 ) -> & ' r mut Vec < BoundRegionScope < ' tcx > >
418418 where
419- D : TypeRelatingDelegate < ' tcx > ,
419+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
420420 {
421421 & mut relate. a_scopes
422422 }
423423
424424 fn relate_generalized_ty < D > (
425425 & self ,
426- relate : & mut TypeRelating < ' _ , ' tcx , D > ,
426+ relate : & mut TypeRelating < ' cx , ' tcx , D > ,
427427 generalized_ty : Ty < ' tcx > ,
428428 ) -> RelateResult < ' tcx , Ty < ' tcx > >
429429 where
430- D : TypeRelatingDelegate < ' tcx > ,
430+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
431431 {
432432 relate. relate ( & generalized_ty, & self . value_ty ( ) )
433433 }
@@ -445,32 +445,32 @@ impl VidValuePair<'tcx> for (Ty<'tcx>, ty::TyVid) {
445445
446446 fn vid_scopes < D > (
447447 & self ,
448- relate : & ' r mut TypeRelating < ' _ , ' tcx , D > ,
448+ relate : & ' r mut TypeRelating < ' cx , ' tcx , D > ,
449449 ) -> & ' r mut Vec < BoundRegionScope < ' tcx > >
450450 where
451- D : TypeRelatingDelegate < ' tcx > ,
451+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
452452 {
453453 & mut relate. b_scopes
454454 }
455455
456456 fn relate_generalized_ty < D > (
457457 & self ,
458- relate : & mut TypeRelating < ' _ , ' tcx , D > ,
458+ relate : & mut TypeRelating < ' cx , ' tcx , D > ,
459459 generalized_ty : Ty < ' tcx > ,
460460 ) -> RelateResult < ' tcx , Ty < ' tcx > >
461461 where
462- D : TypeRelatingDelegate < ' tcx > ,
462+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
463463 {
464464 relate. relate ( & self . value_ty ( ) , & generalized_ty)
465465 }
466466}
467467
468- impl < D > TypeRelation < ' tcx > for TypeRelating < ' me , ' tcx , D >
468+ impl < D > TypeRelation < ' tcx > for TypeRelating < ' cx , ' tcx , D >
469469where
470- D : TypeRelatingDelegate < ' tcx > ,
470+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
471471{
472472 fn tcx ( & self ) -> TyCtxt < ' tcx > {
473- self . infcx . tcx
473+ self . delegate . infcx ( ) . tcx
474474 }
475475
476476 // FIXME(oli-obk): not sure how to get the correct ParamEnv
@@ -509,10 +509,10 @@ where
509509 }
510510
511511 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) ;
513513
514514 if !D :: forbid_inference_vars ( ) {
515- b = self . infcx . shallow_resolve ( b) ;
515+ b = self . delegate . infcx ( ) . shallow_resolve ( b) ;
516516 }
517517
518518 if a == b {
@@ -553,7 +553,7 @@ where
553553 debug ! ( "tys(a={:?}, b={:?}, variance={:?})" , a, b, self . ambient_variance) ;
554554
555555 // 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)
557557 }
558558 }
559559 }
@@ -589,10 +589,10 @@ where
589589 a : & ' tcx ty:: Const < ' tcx > ,
590590 mut b : & ' tcx ty:: Const < ' tcx > ,
591591 ) -> RelateResult < ' tcx , & ' tcx ty:: Const < ' tcx > > {
592- let a = self . infcx . shallow_resolve ( a) ;
592+ let a = self . delegate . infcx ( ) . shallow_resolve ( a) ;
593593
594594 if !D :: forbid_inference_vars ( ) {
595- b = self . infcx . shallow_resolve ( b) ;
595+ b = self . delegate . infcx ( ) . shallow_resolve ( b) ;
596596 }
597597
598598 match b. val {
@@ -601,7 +601,7 @@ where
601601 bug ! ( "unexpected inference var {:?}" , b)
602602 }
603603 // 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) ,
605605 }
606606 }
607607
@@ -717,9 +717,9 @@ where
717717 }
718718}
719719
720- impl < ' tcx , D > ConstEquateRelation < ' tcx > for TypeRelating < ' _ , ' tcx , D >
720+ impl < D > ConstEquateRelation < ' tcx > for TypeRelating < ' cx , ' tcx , D >
721721where
722- D : TypeRelatingDelegate < ' tcx > ,
722+ D : TypeRelatingDelegate < ' cx , ' tcx > ,
723723{
724724 fn const_equate_obligation ( & mut self , a : & ' tcx ty:: Const < ' tcx > , b : & ' tcx ty:: Const < ' tcx > ) {
725725 self . delegate . const_equate ( a, b) ;
@@ -788,7 +788,7 @@ impl<'me, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'me, 'tcx> {
788788/// [blog post]: https://is.gd/0hKvIr
789789struct TypeGeneralizer < ' me , ' tcx , D >
790790where
791- D : TypeRelatingDelegate < ' tcx > ,
791+ D : TypeRelatingDelegate < ' me , ' tcx > ,
792792{
793793 infcx : & ' me InferCtxt < ' me , ' tcx > ,
794794
@@ -813,10 +813,10 @@ where
813813
814814impl < D > TypeRelation < ' tcx > for TypeGeneralizer < ' me , ' tcx , D >
815815where
816- D : TypeRelatingDelegate < ' tcx > ,
816+ D : TypeRelatingDelegate < ' me , ' tcx > ,
817817{
818818 fn tcx ( & self ) -> TyCtxt < ' tcx > {
819- self . infcx . tcx
819+ self . delegate . infcx ( ) . tcx
820820 }
821821
822822 // FIXME(oli-obk): not sure how to get the correct ParamEnv
0 commit comments