@@ -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 ;
@@ -811,13 +811,13 @@ impl<'tcx> InferCtxt<'tcx> {
811811 vars. extend (
812812 ( 0 ..inner. int_unification_table ( ) . len ( ) )
813813 . map ( |i| ty:: IntVid :: from_u32 ( i as u32 ) )
814- . filter ( |& vid| inner. int_unification_table ( ) . probe_value ( vid) . is_none ( ) )
814+ . filter ( |& vid| inner. int_unification_table ( ) . probe_value ( vid) . is_unknown ( ) )
815815 . map ( |v| Ty :: new_int_var ( self . tcx , v) ) ,
816816 ) ;
817817 vars. extend (
818818 ( 0 ..inner. float_unification_table ( ) . len ( ) )
819819 . map ( |i| ty:: FloatVid :: from_u32 ( i as u32 ) )
820- . filter ( |& vid| inner. float_unification_table ( ) . probe_value ( vid) . is_none ( ) )
820+ . filter ( |& vid| inner. float_unification_table ( ) . probe_value ( vid) . is_unknown ( ) )
821821 . map ( |v| Ty :: new_float_var ( self . tcx , v) ) ,
822822 ) ;
823823 vars
@@ -1025,14 +1025,28 @@ impl<'tcx> InferCtxt<'tcx> {
10251025 ty:: Const :: new_var ( self . tcx , vid, ty)
10261026 }
10271027
1028+ pub fn next_const_var_id ( & self , origin : ConstVariableOrigin ) -> ConstVid {
1029+ self . inner
1030+ . borrow_mut ( )
1031+ . const_unification_table ( )
1032+ . new_key ( ConstVariableValue :: Unknown { origin, universe : self . universe ( ) } )
1033+ . vid
1034+ }
1035+
1036+ fn next_int_var_id ( & self ) -> IntVid {
1037+ self . inner . borrow_mut ( ) . int_unification_table ( ) . new_key ( ty:: IntVarValue :: Unknown )
1038+ }
1039+
10281040 pub fn next_int_var ( & self ) -> Ty < ' tcx > {
1029- let vid = self . inner . borrow_mut ( ) . int_unification_table ( ) . new_key ( None ) ;
1030- Ty :: new_int_var ( self . tcx , vid)
1041+ Ty :: new_int_var ( self . tcx , self . next_int_var_id ( ) )
1042+ }
1043+
1044+ fn next_float_var_id ( & self ) -> FloatVid {
1045+ self . inner . borrow_mut ( ) . float_unification_table ( ) . new_key ( ty:: FloatVarValue :: Unknown )
10311046 }
10321047
10331048 pub fn next_float_var ( & self ) -> Ty < ' tcx > {
1034- let vid = self . inner . borrow_mut ( ) . float_unification_table ( ) . new_key ( None ) ;
1035- Ty :: new_float_var ( self . tcx , vid)
1049+ Ty :: new_float_var ( self . tcx , self . next_float_var_id ( ) )
10361050 }
10371051
10381052 /// Creates a fresh region variable with the next available index.
@@ -1258,19 +1272,18 @@ impl<'tcx> InferCtxt<'tcx> {
12581272 known. map ( |t| self . shallow_resolve ( t) )
12591273 }
12601274
1261- ty:: IntVar ( v) => self
1262- . inner
1263- . borrow_mut ( )
1264- . int_unification_table ( )
1265- . probe_value ( v)
1266- . map ( |v| v. to_type ( self . tcx ) ) ,
1275+ ty:: IntVar ( v) => match self . inner . borrow_mut ( ) . int_unification_table ( ) . probe_value ( v) {
1276+ ty:: IntVarValue :: Unknown => None ,
1277+ ty:: IntVarValue :: IntType ( ty) => Some ( Ty :: new_int ( self . tcx , ty) ) ,
1278+ ty:: IntVarValue :: UintType ( ty) => Some ( Ty :: new_uint ( self . tcx , ty) ) ,
1279+ } ,
12671280
1268- ty:: FloatVar ( v) => self
1269- . inner
1270- . borrow_mut ( )
1271- . float_unification_table ( )
1272- . probe_value ( v )
1273- . map ( |v| v . to_type ( self . tcx ) ) ,
1281+ ty:: FloatVar ( v) => {
1282+ match self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v ) {
1283+ ty :: FloatVarValue :: Unknown => None ,
1284+ ty :: FloatVarValue :: Known ( ty ) => Some ( Ty :: new_float ( self . tcx , ty ) ) ,
1285+ }
1286+ }
12741287
12751288 ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => None ,
12761289 }
@@ -1321,21 +1334,26 @@ impl<'tcx> InferCtxt<'tcx> {
13211334 /// or else the root int var in the unification table.
13221335 pub fn opportunistic_resolve_int_var ( & self , vid : ty:: IntVid ) -> Ty < ' tcx > {
13231336 let mut inner = self . inner . borrow_mut ( ) ;
1324- if let Some ( value) = inner. int_unification_table ( ) . probe_value ( vid) {
1325- value. to_type ( self . tcx )
1326- } else {
1327- Ty :: new_int_var ( self . tcx , inner. int_unification_table ( ) . find ( vid) )
1337+ let value = inner. int_unification_table ( ) . probe_value ( vid) ;
1338+ match value {
1339+ ty:: IntVarValue :: IntType ( ty) => Ty :: new_int ( self . tcx , ty) ,
1340+ ty:: IntVarValue :: UintType ( ty) => Ty :: new_uint ( self . tcx , ty) ,
1341+ ty:: IntVarValue :: Unknown => {
1342+ Ty :: new_int_var ( self . tcx , inner. int_unification_table ( ) . find ( vid) )
1343+ }
13281344 }
13291345 }
13301346
13311347 /// Resolves a float var to a rigid int type, if it was constrained to one,
13321348 /// or else the root float var in the unification table.
13331349 pub fn opportunistic_resolve_float_var ( & self , vid : ty:: FloatVid ) -> Ty < ' tcx > {
13341350 let mut inner = self . inner . borrow_mut ( ) ;
1335- if let Some ( value) = inner. float_unification_table ( ) . probe_value ( vid) {
1336- value. to_type ( self . tcx )
1337- } else {
1338- Ty :: new_float_var ( self . tcx , inner. float_unification_table ( ) . find ( vid) )
1351+ let value = inner. float_unification_table ( ) . probe_value ( vid) ;
1352+ match value {
1353+ ty:: FloatVarValue :: Known ( ty) => Ty :: new_float ( self . tcx , ty) ,
1354+ ty:: FloatVarValue :: Unknown => {
1355+ Ty :: new_float_var ( self . tcx , inner. float_unification_table ( ) . find ( vid) )
1356+ }
13391357 }
13401358 }
13411359
@@ -1626,15 +1644,15 @@ impl<'tcx> InferCtxt<'tcx> {
16261644 // If `inlined_probe_value` returns a value it's always a
16271645 // `ty::Int(_)` or `ty::UInt(_)`, which never matches a
16281646 // `ty::Infer(_)`.
1629- self . inner . borrow_mut ( ) . int_unification_table ( ) . inlined_probe_value ( v) . is_some ( )
1647+ ! self . inner . borrow_mut ( ) . int_unification_table ( ) . inlined_probe_value ( v) . is_unknown ( )
16301648 }
16311649
16321650 TyOrConstInferVar :: TyFloat ( v) => {
16331651 // If `probe_value` returns a value it's always a
16341652 // `ty::Float(_)`, which never matches a `ty::Infer(_)`.
16351653 //
16361654 // Not `inlined_probe_value(v)` because this call site is colder.
1637- self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) . is_some ( )
1655+ ! self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) . is_unknown ( )
16381656 }
16391657
16401658 TyOrConstInferVar :: Const ( v) => {
0 commit comments