@@ -56,49 +56,46 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
56
56
}
57
57
}
58
58
59
- fn freshen_ty < F > ( & mut self , opt_ty : Option < Ty < ' tcx > > , key : ty:: InferTy , mk_fresh : F ) -> Ty < ' tcx >
59
+ fn freshen_ty < F > ( & mut self , input : Result < Ty < ' tcx > , ty:: InferTy > , mk_fresh : F ) -> Ty < ' tcx >
60
60
where
61
61
F : FnOnce ( u32 ) -> Ty < ' tcx > ,
62
62
{
63
- if let Some ( ty) = opt_ty {
64
- return ty. fold_with ( self ) ;
65
- }
66
-
67
- match self . ty_freshen_map . entry ( key) {
68
- Entry :: Occupied ( entry) => * entry. get ( ) ,
69
- Entry :: Vacant ( entry) => {
70
- let index = self . ty_freshen_count ;
71
- self . ty_freshen_count += 1 ;
72
- let t = mk_fresh ( index) ;
73
- entry. insert ( t) ;
74
- t
75
- }
63
+ match input {
64
+ Ok ( ty) => ty. fold_with ( self ) ,
65
+ Err ( key) => match self . ty_freshen_map . entry ( key) {
66
+ Entry :: Occupied ( entry) => * entry. get ( ) ,
67
+ Entry :: Vacant ( entry) => {
68
+ let index = self . ty_freshen_count ;
69
+ self . ty_freshen_count += 1 ;
70
+ let t = mk_fresh ( index) ;
71
+ entry. insert ( t) ;
72
+ t
73
+ }
74
+ } ,
76
75
}
77
76
}
78
77
79
78
fn freshen_const < F > (
80
79
& mut self ,
81
- opt_ct : Option < ty:: Const < ' tcx > > ,
82
- key : ty:: InferConst ,
80
+ input : Result < ty:: Const < ' tcx > , ty:: InferConst > ,
83
81
freshener : F ,
84
82
ty : Ty < ' tcx > ,
85
83
) -> ty:: Const < ' tcx >
86
84
where
87
85
F : FnOnce ( u32 ) -> ty:: InferConst ,
88
86
{
89
- if let Some ( ct) = opt_ct {
90
- return ct. fold_with ( self ) ;
91
- }
92
-
93
- match self . const_freshen_map . entry ( key) {
94
- Entry :: Occupied ( entry) => * entry. get ( ) ,
95
- Entry :: Vacant ( entry) => {
96
- let index = self . const_freshen_count ;
97
- self . const_freshen_count += 1 ;
98
- let ct = ty:: Const :: new_infer ( self . infcx . tcx , freshener ( index) , ty) ;
99
- entry. insert ( ct) ;
100
- ct
101
- }
87
+ match input {
88
+ Ok ( ct) => ct. fold_with ( self ) ,
89
+ Err ( key) => match self . const_freshen_map . entry ( key) {
90
+ Entry :: Occupied ( entry) => * entry. get ( ) ,
91
+ Entry :: Vacant ( entry) => {
92
+ let index = self . const_freshen_count ;
93
+ self . const_freshen_count += 1 ;
94
+ let ct = ty:: Const :: new_infer ( self . infcx . tcx , freshener ( index) , ty) ;
95
+ entry. insert ( ct) ;
96
+ ct
97
+ }
98
+ } ,
102
99
}
103
100
}
104
101
}
@@ -146,30 +143,25 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
146
143
fn fold_const ( & mut self , ct : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
147
144
match ct. kind ( ) {
148
145
ty:: ConstKind :: Infer ( ty:: InferConst :: Var ( v) ) => {
149
- let opt_ct = self
150
- . infcx
151
- . inner
152
- . borrow_mut ( )
153
- . const_unification_table ( )
154
- . probe_value ( v)
155
- . val
156
- . known ( ) ;
157
- self . freshen_const ( opt_ct, ty:: InferConst :: Var ( v) , ty:: InferConst :: Fresh , ct. ty ( ) )
146
+ let mut inner = self . infcx . inner . borrow_mut ( ) ;
147
+ let input =
148
+ inner. const_unification_table ( ) . probe_value ( v) . val . known ( ) . ok_or_else ( || {
149
+ ty:: InferConst :: Var ( inner. const_unification_table ( ) . find ( v) . vid )
150
+ } ) ;
151
+ drop ( inner) ;
152
+ self . freshen_const ( input, ty:: InferConst :: Fresh , ct. ty ( ) )
158
153
}
159
154
ty:: ConstKind :: Infer ( ty:: InferConst :: EffectVar ( v) ) => {
160
- let opt_ct = self
161
- . infcx
162
- . inner
163
- . borrow_mut ( )
155
+ let mut inner = self . infcx . inner . borrow_mut ( ) ;
156
+ let input = inner
164
157
. effect_unification_table ( )
165
158
. probe_value ( v)
166
- . map ( |effect| effect. as_const ( self . infcx . tcx ) ) ;
167
- self . freshen_const (
168
- opt_ct,
169
- ty:: InferConst :: EffectVar ( v) ,
170
- ty:: InferConst :: Fresh ,
171
- ct. ty ( ) ,
172
- )
159
+ . map ( |effect| effect. as_const ( self . infcx . tcx ) )
160
+ . ok_or_else ( || {
161
+ ty:: InferConst :: EffectVar ( inner. effect_unification_table ( ) . find ( v) . vid )
162
+ } ) ;
163
+ drop ( inner) ;
164
+ self . freshen_const ( input, ty:: InferConst :: Fresh , ct. ty ( ) )
173
165
}
174
166
ty:: ConstKind :: Infer ( ty:: InferConst :: Fresh ( i) ) => {
175
167
if i >= self . const_freshen_count {
@@ -202,35 +194,37 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
202
194
fn fold_infer_ty ( & mut self , v : ty:: InferTy ) -> Option < Ty < ' tcx > > {
203
195
match v {
204
196
ty:: TyVar ( v) => {
205
- let opt_ty = self . infcx . inner . borrow_mut ( ) . type_variables ( ) . probe ( v) . known ( ) ;
206
- Some ( self . freshen_ty ( opt_ty, ty:: TyVar ( v) , |n| Ty :: new_fresh ( self . infcx . tcx , n) ) )
197
+ let mut inner = self . infcx . inner . borrow_mut ( ) ;
198
+ let input = inner
199
+ . type_variables ( )
200
+ . probe ( v)
201
+ . known ( )
202
+ . ok_or_else ( || ty:: TyVar ( inner. type_variables ( ) . root_var ( v) ) ) ;
203
+ drop ( inner) ;
204
+ Some ( self . freshen_ty ( input, |n| Ty :: new_fresh ( self . infcx . tcx , n) ) )
207
205
}
208
206
209
- ty:: IntVar ( v) => Some (
210
- self . freshen_ty (
211
- self . infcx
212
- . inner
213
- . borrow_mut ( )
214
- . int_unification_table ( )
215
- . probe_value ( v)
216
- . map ( |v| v. to_type ( self . infcx . tcx ) ) ,
217
- ty:: IntVar ( v) ,
218
- |n| Ty :: new_fresh_int ( self . infcx . tcx , n) ,
219
- ) ,
220
- ) ,
221
-
222
- ty:: FloatVar ( v) => Some (
223
- self . freshen_ty (
224
- self . infcx
225
- . inner
226
- . borrow_mut ( )
227
- . float_unification_table ( )
228
- . probe_value ( v)
229
- . map ( |v| v. to_type ( self . infcx . tcx ) ) ,
230
- ty:: FloatVar ( v) ,
231
- |n| Ty :: new_fresh_float ( self . infcx . tcx , n) ,
232
- ) ,
233
- ) ,
207
+ ty:: IntVar ( v) => {
208
+ let mut inner = self . infcx . inner . borrow_mut ( ) ;
209
+ let input = inner
210
+ . int_unification_table ( )
211
+ . probe_value ( v)
212
+ . map ( |v| v. to_type ( self . infcx . tcx ) )
213
+ . ok_or_else ( || ty:: IntVar ( inner. int_unification_table ( ) . find ( v) ) ) ;
214
+ drop ( inner) ;
215
+ Some ( self . freshen_ty ( input, |n| Ty :: new_fresh_int ( self . infcx . tcx , n) ) )
216
+ }
217
+
218
+ ty:: FloatVar ( v) => {
219
+ let mut inner = self . infcx . inner . borrow_mut ( ) ;
220
+ let input = inner
221
+ . float_unification_table ( )
222
+ . probe_value ( v)
223
+ . map ( |v| v. to_type ( self . infcx . tcx ) )
224
+ . ok_or_else ( || ty:: FloatVar ( inner. float_unification_table ( ) . find ( v) ) ) ;
225
+ drop ( inner) ;
226
+ Some ( self . freshen_ty ( input, |n| Ty :: new_fresh_float ( self . infcx . tcx , n) ) )
227
+ }
234
228
235
229
ty:: FreshTy ( ct) | ty:: FreshIntTy ( ct) | ty:: FreshFloatTy ( ct) => {
236
230
if ct >= self . ty_freshen_count {
0 commit comments