@@ -56,49 +56,46 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
5656 }
5757 }
5858
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 >
6060 where
6161 F : FnOnce ( u32 ) -> Ty < ' tcx > ,
6262 {
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+ } ,
7675 }
7776 }
7877
7978 fn freshen_const < F > (
8079 & mut self ,
81- opt_ct : Option < ty:: Const < ' tcx > > ,
82- key : ty:: InferConst ,
80+ input : Result < ty:: Const < ' tcx > , ty:: InferConst > ,
8381 freshener : F ,
8482 ty : Ty < ' tcx > ,
8583 ) -> ty:: Const < ' tcx >
8684 where
8785 F : FnOnce ( u32 ) -> ty:: InferConst ,
8886 {
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+ } ,
10299 }
103100 }
104101}
@@ -146,19 +143,22 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
146143 fn fold_const ( & mut self , ct : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
147144 match ct. kind ( ) {
148145 ty:: ConstKind :: Infer ( ty:: InferConst :: Var ( v) ) => {
149- let opt_ct =
150- self . infcx . inner . borrow_mut ( ) . const_unification_table ( ) . probe_value ( v) . known ( ) ;
151- 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) . 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 ( ) )
152153 }
153154 ty:: ConstKind :: Infer ( ty:: InferConst :: EffectVar ( v) ) => {
154- let opt_ct =
155- self . infcx . inner . borrow_mut ( ) . effect_unification_table ( ) . probe_value ( v) . known ( ) ;
156- self . freshen_const (
157- opt_ct,
158- ty:: InferConst :: EffectVar ( v) ,
159- ty:: InferConst :: Fresh ,
160- ct. ty ( ) ,
161- )
155+ let mut inner = self . infcx . inner . borrow_mut ( ) ;
156+ let input =
157+ inner. effect_unification_table ( ) . probe_value ( v) . known ( ) . ok_or_else ( || {
158+ ty:: InferConst :: EffectVar ( inner. effect_unification_table ( ) . find ( v) . vid )
159+ } ) ;
160+ drop ( inner) ;
161+ self . freshen_const ( input, ty:: InferConst :: Fresh , ct. ty ( ) )
162162 }
163163 ty:: ConstKind :: Infer ( ty:: InferConst :: Fresh ( i) ) => {
164164 if i >= self . const_freshen_count {
@@ -191,35 +191,37 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
191191 fn fold_infer_ty ( & mut self , v : ty:: InferTy ) -> Option < Ty < ' tcx > > {
192192 match v {
193193 ty:: TyVar ( v) => {
194- let opt_ty = self . infcx . inner . borrow_mut ( ) . type_variables ( ) . probe ( v) . known ( ) ;
195- Some ( self . freshen_ty ( opt_ty, ty:: TyVar ( v) , |n| Ty :: new_fresh ( self . infcx . tcx , n) ) )
194+ let mut inner = self . infcx . inner . borrow_mut ( ) ;
195+ let input = inner
196+ . type_variables ( )
197+ . probe ( v)
198+ . known ( )
199+ . ok_or_else ( || ty:: TyVar ( inner. type_variables ( ) . root_var ( v) ) ) ;
200+ drop ( inner) ;
201+ Some ( self . freshen_ty ( input, |n| Ty :: new_fresh ( self . infcx . tcx , n) ) )
196202 }
197203
198- ty:: IntVar ( v) => Some (
199- self . freshen_ty (
200- self . infcx
201- . inner
202- . borrow_mut ( )
203- . int_unification_table ( )
204- . probe_value ( v)
205- . map ( |v| v. to_type ( self . infcx . tcx ) ) ,
206- ty:: IntVar ( v) ,
207- |n| Ty :: new_fresh_int ( self . infcx . tcx , n) ,
208- ) ,
209- ) ,
210-
211- ty:: FloatVar ( v) => Some (
212- self . freshen_ty (
213- self . infcx
214- . inner
215- . borrow_mut ( )
216- . float_unification_table ( )
217- . probe_value ( v)
218- . map ( |v| v. to_type ( self . infcx . tcx ) ) ,
219- ty:: FloatVar ( v) ,
220- |n| Ty :: new_fresh_float ( self . infcx . tcx , n) ,
221- ) ,
222- ) ,
204+ ty:: IntVar ( v) => {
205+ let mut inner = self . infcx . inner . borrow_mut ( ) ;
206+ let input = inner
207+ . int_unification_table ( )
208+ . probe_value ( v)
209+ . map ( |v| v. to_type ( self . infcx . tcx ) )
210+ . ok_or_else ( || ty:: IntVar ( inner. int_unification_table ( ) . find ( v) ) ) ;
211+ drop ( inner) ;
212+ Some ( self . freshen_ty ( input, |n| Ty :: new_fresh_int ( self . infcx . tcx , n) ) )
213+ }
214+
215+ ty:: FloatVar ( v) => {
216+ let mut inner = self . infcx . inner . borrow_mut ( ) ;
217+ let input = inner
218+ . float_unification_table ( )
219+ . probe_value ( v)
220+ . map ( |v| v. to_type ( self . infcx . tcx ) )
221+ . ok_or_else ( || ty:: FloatVar ( inner. float_unification_table ( ) . find ( v) ) ) ;
222+ drop ( inner) ;
223+ Some ( self . freshen_ty ( input, |n| Ty :: new_fresh_float ( self . infcx . tcx , n) ) )
224+ }
223225
224226 ty:: FreshTy ( ct) | ty:: FreshIntTy ( ct) | ty:: FreshFloatTy ( ct) => {
225227 if ct >= self . ty_freshen_count {
0 commit comments