@@ -29,9 +29,9 @@ use rustc_errors::{Diag, DiagCtxt, ErrorGuaranteed};
2929use rustc_hir:: def_id:: { DefId , LocalDefId } ;
3030use rustc_macros:: extension;
3131use rustc_middle:: infer:: canonical:: { Canonical , CanonicalVarValues } ;
32+ use rustc_middle:: infer:: unify_key:: ConstVariableOrigin ;
3233use rustc_middle:: infer:: unify_key:: ConstVariableValue ;
3334use rustc_middle:: infer:: unify_key:: EffectVarValue ;
34- use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ToType } ;
3535use rustc_middle:: infer:: unify_key:: { ConstVidKey , EffectVidKey } ;
3636use rustc_middle:: mir:: interpret:: { ErrorHandled , EvalToValTreeResult } ;
3737use rustc_middle:: mir:: ConstraintCategory ;
@@ -813,13 +813,13 @@ impl<'tcx> InferCtxt<'tcx> {
813813 vars. extend (
814814 ( 0 ..inner. int_unification_table ( ) . len ( ) )
815815 . map ( |i| ty:: IntVid :: from_u32 ( i as u32 ) )
816- . filter ( |& vid| inner. int_unification_table ( ) . probe_value ( vid) . is_none ( ) )
816+ . filter ( |& vid| inner. int_unification_table ( ) . probe_value ( vid) . is_unknown ( ) )
817817 . map ( |v| Ty :: new_int_var ( self . tcx , v) ) ,
818818 ) ;
819819 vars. extend (
820820 ( 0 ..inner. float_unification_table ( ) . len ( ) )
821821 . map ( |i| ty:: FloatVid :: from_u32 ( i as u32 ) )
822- . filter ( |& vid| inner. float_unification_table ( ) . probe_value ( vid) . is_none ( ) )
822+ . filter ( |& vid| inner. float_unification_table ( ) . probe_value ( vid) . is_unknown ( ) )
823823 . map ( |v| Ty :: new_float_var ( self . tcx , v) ) ,
824824 ) ;
825825 vars
@@ -1027,14 +1027,28 @@ impl<'tcx> InferCtxt<'tcx> {
10271027 ty:: Const :: new_var ( self . tcx , vid, ty)
10281028 }
10291029
1030+ pub fn next_const_var_id ( & self , origin : ConstVariableOrigin ) -> ConstVid {
1031+ self . inner
1032+ . borrow_mut ( )
1033+ . const_unification_table ( )
1034+ . new_key ( ConstVariableValue :: Unknown { origin, universe : self . universe ( ) } )
1035+ . vid
1036+ }
1037+
1038+ fn next_int_var_id ( & self ) -> IntVid {
1039+ self . inner . borrow_mut ( ) . int_unification_table ( ) . new_key ( ty:: IntVarValue :: Unknown )
1040+ }
1041+
10301042 pub fn next_int_var ( & self ) -> Ty < ' tcx > {
1031- let vid = self . inner . borrow_mut ( ) . int_unification_table ( ) . new_key ( None ) ;
1032- Ty :: new_int_var ( self . tcx , vid)
1043+ Ty :: new_int_var ( self . tcx , self . next_int_var_id ( ) )
1044+ }
1045+
1046+ fn next_float_var_id ( & self ) -> FloatVid {
1047+ self . inner . borrow_mut ( ) . float_unification_table ( ) . new_key ( ty:: FloatVarValue :: Unknown )
10331048 }
10341049
10351050 pub fn next_float_var ( & self ) -> Ty < ' tcx > {
1036- let vid = self . inner . borrow_mut ( ) . float_unification_table ( ) . new_key ( None ) ;
1037- Ty :: new_float_var ( self . tcx , vid)
1051+ Ty :: new_float_var ( self . tcx , self . next_float_var_id ( ) )
10381052 }
10391053
10401054 /// Creates a fresh region variable with the next available index.
@@ -1260,19 +1274,18 @@ impl<'tcx> InferCtxt<'tcx> {
12601274 known. map ( |t| self . shallow_resolve ( t) )
12611275 }
12621276
1263- ty:: IntVar ( v) => self
1264- . inner
1265- . borrow_mut ( )
1266- . int_unification_table ( )
1267- . probe_value ( v)
1268- . map ( |v| v. to_type ( self . tcx ) ) ,
1277+ ty:: IntVar ( v) => match self . inner . borrow_mut ( ) . int_unification_table ( ) . probe_value ( v) {
1278+ ty:: IntVarValue :: Unknown => None ,
1279+ ty:: IntVarValue :: IntType ( ty) => Some ( Ty :: new_int ( self . tcx , ty) ) ,
1280+ ty:: IntVarValue :: UintType ( ty) => Some ( Ty :: new_uint ( self . tcx , ty) ) ,
1281+ } ,
12691282
1270- ty:: FloatVar ( v) => self
1271- . inner
1272- . borrow_mut ( )
1273- . float_unification_table ( )
1274- . probe_value ( v )
1275- . map ( |v| v . to_type ( self . tcx ) ) ,
1283+ ty:: FloatVar ( v) => {
1284+ match self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v ) {
1285+ ty :: FloatVarValue :: Unknown => None ,
1286+ ty :: FloatVarValue :: Known ( ty ) => Some ( Ty :: new_float ( self . tcx , ty ) ) ,
1287+ }
1288+ }
12761289
12771290 ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => None ,
12781291 }
@@ -1323,21 +1336,26 @@ impl<'tcx> InferCtxt<'tcx> {
13231336 /// or else the root int var in the unification table.
13241337 pub fn opportunistic_resolve_int_var ( & self , vid : ty:: IntVid ) -> Ty < ' tcx > {
13251338 let mut inner = self . inner . borrow_mut ( ) ;
1326- if let Some ( value) = inner. int_unification_table ( ) . probe_value ( vid) {
1327- value. to_type ( self . tcx )
1328- } else {
1329- Ty :: new_int_var ( self . tcx , inner. int_unification_table ( ) . find ( vid) )
1339+ let value = inner. int_unification_table ( ) . probe_value ( vid) ;
1340+ match value {
1341+ ty:: IntVarValue :: IntType ( ty) => Ty :: new_int ( self . tcx , ty) ,
1342+ ty:: IntVarValue :: UintType ( ty) => Ty :: new_uint ( self . tcx , ty) ,
1343+ ty:: IntVarValue :: Unknown => {
1344+ Ty :: new_int_var ( self . tcx , inner. int_unification_table ( ) . find ( vid) )
1345+ }
13301346 }
13311347 }
13321348
13331349 /// Resolves a float var to a rigid int type, if it was constrained to one,
13341350 /// or else the root float var in the unification table.
13351351 pub fn opportunistic_resolve_float_var ( & self , vid : ty:: FloatVid ) -> Ty < ' tcx > {
13361352 let mut inner = self . inner . borrow_mut ( ) ;
1337- if let Some ( value) = inner. float_unification_table ( ) . probe_value ( vid) {
1338- value. to_type ( self . tcx )
1339- } else {
1340- Ty :: new_float_var ( self . tcx , inner. float_unification_table ( ) . find ( vid) )
1353+ let value = inner. float_unification_table ( ) . probe_value ( vid) ;
1354+ match value {
1355+ ty:: FloatVarValue :: Known ( ty) => Ty :: new_float ( self . tcx , ty) ,
1356+ ty:: FloatVarValue :: Unknown => {
1357+ Ty :: new_float_var ( self . tcx , inner. float_unification_table ( ) . find ( vid) )
1358+ }
13411359 }
13421360 }
13431361
@@ -1628,15 +1646,15 @@ impl<'tcx> InferCtxt<'tcx> {
16281646 // If `inlined_probe_value` returns a value it's always a
16291647 // `ty::Int(_)` or `ty::UInt(_)`, which never matches a
16301648 // `ty::Infer(_)`.
1631- self . inner . borrow_mut ( ) . int_unification_table ( ) . inlined_probe_value ( v) . is_some ( )
1649+ ! self . inner . borrow_mut ( ) . int_unification_table ( ) . inlined_probe_value ( v) . is_unknown ( )
16321650 }
16331651
16341652 TyOrConstInferVar :: TyFloat ( v) => {
16351653 // If `probe_value` returns a value it's always a
16361654 // `ty::Float(_)`, which never matches a `ty::Infer(_)`.
16371655 //
16381656 // Not `inlined_probe_value(v)` because this call site is colder.
1639- self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) . is_some ( )
1657+ ! self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) . is_unknown ( )
16401658 }
16411659
16421660 TyOrConstInferVar :: Const ( v) => {
0 commit comments