@@ -29,9 +29,9 @@ use rustc_errors::{Diag, DiagCtxt, ErrorGuaranteed};
29
29
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
30
30
use rustc_macros:: extension;
31
31
use rustc_middle:: infer:: canonical:: { Canonical , CanonicalVarValues } ;
32
+ use rustc_middle:: infer:: unify_key:: ConstVariableOrigin ;
32
33
use rustc_middle:: infer:: unify_key:: ConstVariableValue ;
33
34
use rustc_middle:: infer:: unify_key:: EffectVarValue ;
34
- use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ToType } ;
35
35
use rustc_middle:: infer:: unify_key:: { ConstVidKey , EffectVidKey } ;
36
36
use rustc_middle:: mir:: interpret:: { ErrorHandled , EvalToValTreeResult } ;
37
37
use rustc_middle:: mir:: ConstraintCategory ;
@@ -811,13 +811,13 @@ impl<'tcx> InferCtxt<'tcx> {
811
811
vars. extend (
812
812
( 0 ..inner. int_unification_table ( ) . len ( ) )
813
813
. 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 ( ) )
815
815
. map ( |v| Ty :: new_int_var ( self . tcx , v) ) ,
816
816
) ;
817
817
vars. extend (
818
818
( 0 ..inner. float_unification_table ( ) . len ( ) )
819
819
. 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 ( ) )
821
821
. map ( |v| Ty :: new_float_var ( self . tcx , v) ) ,
822
822
) ;
823
823
vars
@@ -1025,14 +1025,28 @@ impl<'tcx> InferCtxt<'tcx> {
1025
1025
ty:: Const :: new_var ( self . tcx , vid, ty)
1026
1026
}
1027
1027
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
+
1028
1040
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 )
1031
1046
}
1032
1047
1033
1048
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 ( ) )
1036
1050
}
1037
1051
1038
1052
/// Creates a fresh region variable with the next available index.
@@ -1258,19 +1272,18 @@ impl<'tcx> InferCtxt<'tcx> {
1258
1272
known. map ( |t| self . shallow_resolve ( t) )
1259
1273
}
1260
1274
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
+ } ,
1267
1280
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
+ }
1274
1287
1275
1288
ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => None ,
1276
1289
}
@@ -1321,21 +1334,26 @@ impl<'tcx> InferCtxt<'tcx> {
1321
1334
/// or else the root int var in the unification table.
1322
1335
pub fn opportunistic_resolve_int_var ( & self , vid : ty:: IntVid ) -> Ty < ' tcx > {
1323
1336
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
+ }
1328
1344
}
1329
1345
}
1330
1346
1331
1347
/// Resolves a float var to a rigid int type, if it was constrained to one,
1332
1348
/// or else the root float var in the unification table.
1333
1349
pub fn opportunistic_resolve_float_var ( & self , vid : ty:: FloatVid ) -> Ty < ' tcx > {
1334
1350
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
+ }
1339
1357
}
1340
1358
}
1341
1359
@@ -1626,15 +1644,15 @@ impl<'tcx> InferCtxt<'tcx> {
1626
1644
// If `inlined_probe_value` returns a value it's always a
1627
1645
// `ty::Int(_)` or `ty::UInt(_)`, which never matches a
1628
1646
// `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 ( )
1630
1648
}
1631
1649
1632
1650
TyOrConstInferVar :: TyFloat ( v) => {
1633
1651
// If `probe_value` returns a value it's always a
1634
1652
// `ty::Float(_)`, which never matches a `ty::Infer(_)`.
1635
1653
//
1636
1654
// 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 ( )
1638
1656
}
1639
1657
1640
1658
TyOrConstInferVar :: Const ( v) => {
0 commit comments