@@ -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 ;
@@ -813,13 +813,13 @@ impl<'tcx> InferCtxt<'tcx> {
813
813
vars. extend (
814
814
( 0 ..inner. int_unification_table ( ) . len ( ) )
815
815
. 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 ( ) )
817
817
. map ( |v| Ty :: new_int_var ( self . tcx , v) ) ,
818
818
) ;
819
819
vars. extend (
820
820
( 0 ..inner. float_unification_table ( ) . len ( ) )
821
821
. 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 ( ) )
823
823
. map ( |v| Ty :: new_float_var ( self . tcx , v) ) ,
824
824
) ;
825
825
vars
@@ -1027,14 +1027,28 @@ impl<'tcx> InferCtxt<'tcx> {
1027
1027
ty:: Const :: new_var ( self . tcx , vid, ty)
1028
1028
}
1029
1029
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
+
1030
1042
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 )
1033
1048
}
1034
1049
1035
1050
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 ( ) )
1038
1052
}
1039
1053
1040
1054
/// Creates a fresh region variable with the next available index.
@@ -1260,19 +1274,18 @@ impl<'tcx> InferCtxt<'tcx> {
1260
1274
known. map ( |t| self . shallow_resolve ( t) )
1261
1275
}
1262
1276
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
+ } ,
1269
1282
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
+ }
1276
1289
1277
1290
ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => None ,
1278
1291
}
@@ -1323,21 +1336,26 @@ impl<'tcx> InferCtxt<'tcx> {
1323
1336
/// or else the root int var in the unification table.
1324
1337
pub fn opportunistic_resolve_int_var ( & self , vid : ty:: IntVid ) -> Ty < ' tcx > {
1325
1338
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
+ }
1330
1346
}
1331
1347
}
1332
1348
1333
1349
/// Resolves a float var to a rigid int type, if it was constrained to one,
1334
1350
/// or else the root float var in the unification table.
1335
1351
pub fn opportunistic_resolve_float_var ( & self , vid : ty:: FloatVid ) -> Ty < ' tcx > {
1336
1352
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
+ }
1341
1359
}
1342
1360
}
1343
1361
@@ -1628,15 +1646,15 @@ impl<'tcx> InferCtxt<'tcx> {
1628
1646
// If `inlined_probe_value` returns a value it's always a
1629
1647
// `ty::Int(_)` or `ty::UInt(_)`, which never matches a
1630
1648
// `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 ( )
1632
1650
}
1633
1651
1634
1652
TyOrConstInferVar :: TyFloat ( v) => {
1635
1653
// If `probe_value` returns a value it's always a
1636
1654
// `ty::Float(_)`, which never matches a `ty::Infer(_)`.
1637
1655
//
1638
1656
// 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 ( )
1640
1658
}
1641
1659
1642
1660
TyOrConstInferVar :: Const ( v) => {
0 commit comments