1- use crate :: ty:: { self , Ty , TyCtxt , TyVid , RegionVid } ;
1+ use crate :: ty:: { self , Ty , TyCtxt , TyVid , IntVid , FloatVid , RegionVid } ;
22use crate :: ty:: fold:: { TypeFoldable , TypeFolder } ;
33
44use super :: InferCtxt ;
@@ -56,7 +56,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
5656 {
5757 debug ! ( "fudge_inference_if_ok(origin={:?})" , origin) ;
5858
59- let ( type_variables , region_vars, value) = self . probe ( |snapshot| {
59+ let ( type_vars , int_vars , float_vars , region_vars, value) = self . probe ( |snapshot| {
6060 match f ( ) {
6161 Ok ( value) => {
6262 let value = self . resolve_type_vars_if_possible ( & value) ;
@@ -67,14 +67,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
6767 // going to be popped, so we will have to
6868 // eliminate any references to them.
6969
70- let type_variables = self . type_variables . borrow_mut ( ) . vars_since_snapshot (
70+ let type_vars = self . type_variables . borrow_mut ( ) . vars_since_snapshot (
7171 & snapshot. type_snapshot ,
7272 ) ;
73+ let int_vars = self . int_unification_table . borrow_mut ( ) . vars_since_snapshot (
74+ & snapshot. int_snapshot ,
75+ ) ;
76+ let float_vars = self . float_unification_table . borrow_mut ( ) . vars_since_snapshot (
77+ & snapshot. float_snapshot ,
78+ ) ;
7379 let region_vars = self . borrow_region_constraints ( ) . vars_since_snapshot (
7480 & snapshot. region_constraints_snapshot ,
7581 ) ;
7682
77- Ok ( ( type_variables , region_vars, value) )
83+ Ok ( ( type_vars , int_vars , float_vars , region_vars, value) )
7884 }
7985 Err ( e) => Err ( e) ,
8086 }
@@ -87,13 +93,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
8793
8894 // Micro-optimization: if no variables have been created, then
8995 // `value` can't refer to any of them. =) So we can just return it.
90- if type_variables. is_empty ( ) && region_vars. is_empty ( ) {
96+ if type_vars. is_empty ( ) &&
97+ int_vars. is_empty ( ) &&
98+ float_vars. is_empty ( ) &&
99+ region_vars. is_empty ( ) {
91100 return Ok ( value) ;
92101 }
93102
94103 let mut fudger = InferenceFudger {
95104 infcx : self ,
96- type_variables : & type_variables,
105+ type_vars : & type_vars,
106+ int_vars : & int_vars,
107+ float_vars : & float_vars,
97108 region_vars : & region_vars,
98109 origin,
99110 } ;
@@ -104,7 +115,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
104115
105116pub struct InferenceFudger < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
106117 infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
107- type_variables : & ' a Range < TyVid > ,
118+ type_vars : & ' a Range < TyVid > ,
119+ int_vars : & ' a Range < IntVid > ,
120+ float_vars : & ' a Range < FloatVid > ,
108121 region_vars : & ' a Range < RegionVid > ,
109122 origin : & ' a RegionVariableOrigin ,
110123}
@@ -117,7 +130,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
117130 fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
118131 match ty. sty {
119132 ty:: Infer ( ty:: InferTy :: TyVar ( vid) ) => {
120- if self . type_variables . contains ( & vid) {
133+ if self . type_vars . contains ( & vid) {
121134 // This variable was created during the fudging.
122135 // Recreate it with a fresh variable here.
123136 let origin = self . infcx . type_variables . borrow ( ) . var_origin ( vid) . clone ( ) ;
@@ -134,6 +147,20 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
134147 ty
135148 }
136149 }
150+ ty:: Infer ( ty:: InferTy :: IntVar ( vid) ) => {
151+ if self . int_vars . contains ( & vid) {
152+ self . infcx . tcx . mk_int_var ( self . infcx . next_int_var_id ( ) )
153+ } else {
154+ ty
155+ }
156+ }
157+ ty:: Infer ( ty:: InferTy :: FloatVar ( vid) ) => {
158+ if self . float_vars . contains ( & vid) {
159+ self . infcx . tcx . mk_float_var ( self . infcx . next_float_var_id ( ) )
160+ } else {
161+ ty
162+ }
163+ }
137164 _ => ty. super_fold_with ( self ) ,
138165 }
139166 }
0 commit comments