@@ -60,7 +60,7 @@ impl<'tcx> InferCtxt<'tcx> {
60
60
{
61
61
Canonicalizer :: canonicalize (
62
62
value,
63
- self ,
63
+ Some ( self ) ,
64
64
self . tcx ,
65
65
& CanonicalizeAllFreeRegionsPreservingUniverses ,
66
66
query_state,
@@ -99,7 +99,7 @@ impl<'tcx> InferCtxt<'tcx> {
99
99
let mut query_state = OriginalQueryValues :: default ( ) ;
100
100
Canonicalizer :: canonicalize (
101
101
value,
102
- self ,
102
+ Some ( self ) ,
103
103
self . tcx ,
104
104
& CanonicalizeQueryResponse ,
105
105
& mut query_state,
@@ -113,7 +113,7 @@ impl<'tcx> InferCtxt<'tcx> {
113
113
let mut query_state = OriginalQueryValues :: default ( ) ;
114
114
Canonicalizer :: canonicalize (
115
115
value,
116
- self ,
116
+ Some ( self ) ,
117
117
self . tcx ,
118
118
& CanonicalizeUserTypeAnnotation ,
119
119
& mut query_state,
@@ -153,11 +153,11 @@ impl<'tcx> InferCtxt<'tcx> {
153
153
self . tcx ,
154
154
param_env,
155
155
query_state,
156
- |query_state| {
156
+ |tcx , param_env , query_state| {
157
157
Canonicalizer :: canonicalize (
158
158
param_env,
159
- self ,
160
- self . tcx ,
159
+ None ,
160
+ tcx,
161
161
& CanonicalizeFreeRegionsOtherThanStatic ,
162
162
query_state,
163
163
)
@@ -167,7 +167,7 @@ impl<'tcx> InferCtxt<'tcx> {
167
167
Canonicalizer :: canonicalize_with_base (
168
168
base,
169
169
value,
170
- self ,
170
+ Some ( self ) ,
171
171
self . tcx ,
172
172
canonicalize_region_mode,
173
173
query_state,
@@ -204,9 +204,10 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
204
204
canonicalizer : & mut Canonicalizer < ' _ , ' tcx > ,
205
205
mut r : ty:: Region < ' tcx > ,
206
206
) -> ty:: Region < ' tcx > {
207
+ let infcx = canonicalizer. infcx . unwrap ( ) ;
208
+
207
209
if let ty:: ReVar ( vid) = * r {
208
- r = canonicalizer
209
- . infcx
210
+ r = infcx
210
211
. inner
211
212
. borrow_mut ( )
212
213
. unwrap_region_constraints ( )
@@ -226,7 +227,8 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
226
227
) ,
227
228
228
229
ty:: ReVar ( vid) => {
229
- let universe = canonicalizer. region_var_universe ( vid) ;
230
+ let universe =
231
+ infcx. inner . borrow_mut ( ) . unwrap_region_constraints ( ) . var_universe ( vid) ;
230
232
canonicalizer. canonical_var_for_region (
231
233
CanonicalVarInfo { kind : CanonicalVarKind :: Region ( universe) } ,
232
234
r,
@@ -319,7 +321,7 @@ impl CanonicalizeMode for CanonicalizeAllFreeRegionsPreservingUniverses {
319
321
canonicalizer : & mut Canonicalizer < ' _ , ' tcx > ,
320
322
r : ty:: Region < ' tcx > ,
321
323
) -> ty:: Region < ' tcx > {
322
- let universe = canonicalizer. infcx . universe_of_region ( r) ;
324
+ let universe = canonicalizer. infcx . unwrap ( ) . universe_of_region ( r) ;
323
325
canonicalizer. canonical_var_for_region (
324
326
CanonicalVarInfo { kind : CanonicalVarKind :: Region ( universe) } ,
325
327
r,
@@ -356,7 +358,8 @@ impl CanonicalizeMode for CanonicalizeFreeRegionsOtherThanStatic {
356
358
}
357
359
358
360
struct Canonicalizer < ' cx , ' tcx > {
359
- infcx : & ' cx InferCtxt < ' tcx > ,
361
+ /// Set to `None` to disable the resolution of inference variables.
362
+ infcx : Option < & ' cx InferCtxt < ' tcx > > ,
360
363
tcx : TyCtxt < ' tcx > ,
361
364
variables : SmallVec < [ CanonicalVarInfo < ' tcx > ; 8 ] > ,
362
365
query_state : & ' cx mut OriginalQueryValues < ' tcx > ,
@@ -410,14 +413,14 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
410
413
// We need to canonicalize the *root* of our ty var.
411
414
// This is so that our canonical response correctly reflects
412
415
// any equated inference vars correctly!
413
- let root_vid = self . infcx . root_var ( vid) ;
416
+ let root_vid = self . infcx . unwrap ( ) . root_var ( vid) ;
414
417
if root_vid != vid {
415
- t = Ty :: new_var ( self . infcx . tcx , root_vid) ;
418
+ t = Ty :: new_var ( self . tcx , root_vid) ;
416
419
vid = root_vid;
417
420
}
418
421
419
422
debug ! ( "canonical: type var found with vid {:?}" , vid) ;
420
- match self . infcx . probe_ty_var ( vid) {
423
+ match self . infcx . unwrap ( ) . probe_ty_var ( vid) {
421
424
// `t` could be a float / int variable; canonicalize that instead.
422
425
Ok ( t) => {
423
426
debug ! ( "(resolved to {:?})" , t) ;
@@ -442,7 +445,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
442
445
}
443
446
444
447
ty:: Infer ( ty:: IntVar ( vid) ) => {
445
- let nt = self . infcx . opportunistic_resolve_int_var ( vid) ;
448
+ let nt = self . infcx . unwrap ( ) . opportunistic_resolve_int_var ( vid) ;
446
449
if nt != t {
447
450
return self . fold_ty ( nt) ;
448
451
} else {
@@ -453,7 +456,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
453
456
}
454
457
}
455
458
ty:: Infer ( ty:: FloatVar ( vid) ) => {
456
- let nt = self . infcx . opportunistic_resolve_float_var ( vid) ;
459
+ let nt = self . infcx . unwrap ( ) . opportunistic_resolve_float_var ( vid) ;
457
460
if nt != t {
458
461
return self . fold_ty ( nt) ;
459
462
} else {
@@ -524,14 +527,14 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
524
527
// We need to canonicalize the *root* of our const var.
525
528
// This is so that our canonical response correctly reflects
526
529
// any equated inference vars correctly!
527
- let root_vid = self . infcx . root_const_var ( vid) ;
530
+ let root_vid = self . infcx . unwrap ( ) . root_const_var ( vid) ;
528
531
if root_vid != vid {
529
- ct = ty:: Const :: new_var ( self . infcx . tcx , root_vid, ct. ty ( ) ) ;
532
+ ct = ty:: Const :: new_var ( self . tcx , root_vid, ct. ty ( ) ) ;
530
533
vid = root_vid;
531
534
}
532
535
533
536
debug ! ( "canonical: const var found with vid {:?}" , vid) ;
534
- match self . infcx . probe_const_var ( vid) {
537
+ match self . infcx . unwrap ( ) . probe_const_var ( vid) {
535
538
Ok ( c) => {
536
539
debug ! ( "(resolved to {:?})" , c) ;
537
540
return self . fold_const ( c) ;
@@ -552,8 +555,8 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
552
555
}
553
556
}
554
557
ty:: ConstKind :: Infer ( InferConst :: EffectVar ( vid) ) => {
555
- match self . infcx . probe_effect_var ( vid) {
556
- Some ( value) => return self . fold_const ( value. as_const ( self . infcx . tcx ) ) ,
558
+ match self . infcx . unwrap ( ) . probe_effect_var ( vid) {
559
+ Some ( value) => return self . fold_const ( value. as_const ( self . tcx ) ) ,
557
560
None => {
558
561
return self . canonicalize_const_var (
559
562
CanonicalVarInfo { kind : CanonicalVarKind :: Effect } ,
@@ -596,7 +599,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
596
599
/// `canonicalize_query` and `canonicalize_response`.
597
600
fn canonicalize < V > (
598
601
value : V ,
599
- infcx : & InferCtxt < ' tcx > ,
602
+ infcx : Option < & InferCtxt < ' tcx > > ,
600
603
tcx : TyCtxt < ' tcx > ,
601
604
canonicalize_region_mode : & dyn CanonicalizeMode ,
602
605
query_state : & mut OriginalQueryValues < ' tcx > ,
@@ -623,7 +626,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
623
626
fn canonicalize_with_base < U , V > (
624
627
base : Canonical < ' tcx , U > ,
625
628
value : V ,
626
- infcx : & InferCtxt < ' tcx > ,
629
+ infcx : Option < & InferCtxt < ' tcx > > ,
627
630
tcx : TyCtxt < ' tcx > ,
628
631
canonicalize_region_mode : & dyn CanonicalizeMode ,
629
632
query_state : & mut OriginalQueryValues < ' tcx > ,
@@ -826,11 +829,6 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
826
829
)
827
830
}
828
831
829
- /// Returns the universe in which `vid` is defined.
830
- fn region_var_universe ( & self , vid : ty:: RegionVid ) -> ty:: UniverseIndex {
831
- self . infcx . inner . borrow_mut ( ) . unwrap_region_constraints ( ) . var_universe ( vid)
832
- }
833
-
834
832
/// Creates a canonical variable (with the given `info`)
835
833
/// representing the region `r`; return a region referencing it.
836
834
fn canonical_var_for_region (
@@ -848,14 +846,8 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
848
846
/// *that*. Otherwise, create a new canonical variable for
849
847
/// `ty_var`.
850
848
fn canonicalize_ty_var ( & mut self , info : CanonicalVarInfo < ' tcx > , ty_var : Ty < ' tcx > ) -> Ty < ' tcx > {
851
- let infcx = self . infcx ;
852
- let bound_to = infcx. shallow_resolve ( ty_var) ;
853
- if bound_to != ty_var {
854
- self . fold_ty ( bound_to)
855
- } else {
856
- let var = self . canonical_var ( info, ty_var. into ( ) ) ;
857
- Ty :: new_bound ( self . tcx , self . binder_index , var. into ( ) )
858
- }
849
+ let var = self . canonical_var ( info, ty_var. into ( ) ) ;
850
+ Ty :: new_bound ( self . tcx , self . binder_index , var. into ( ) )
859
851
}
860
852
861
853
/// Given a type variable `const_var` of the given kind, first check
@@ -867,13 +859,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
867
859
info : CanonicalVarInfo < ' tcx > ,
868
860
const_var : ty:: Const < ' tcx > ,
869
861
) -> ty:: Const < ' tcx > {
870
- let infcx = self . infcx ;
871
- let bound_to = infcx. shallow_resolve ( const_var) ;
872
- if bound_to != const_var {
873
- self . fold_const ( bound_to)
874
- } else {
875
- let var = self . canonical_var ( info, const_var. into ( ) ) ;
876
- ty:: Const :: new_bound ( self . tcx , self . binder_index , var, self . fold_ty ( const_var. ty ( ) ) )
877
- }
862
+ let var = self . canonical_var ( info, const_var. into ( ) ) ;
863
+ ty:: Const :: new_bound ( self . tcx , self . binder_index , var, self . fold_ty ( const_var. ty ( ) ) )
878
864
}
879
865
}
0 commit comments