@@ -61,7 +61,7 @@ use rustc_middle::ty::layout::IntegerExt;
61
61
use rustc_middle:: ty:: { self , Ty , TyCtxt , VariantDef } ;
62
62
use rustc_session:: lint;
63
63
use rustc_span:: { Span , DUMMY_SP } ;
64
- use rustc_target:: abi:: { FieldIdx , Integer , Primitive , Size , VariantIdx , FIRST_VARIANT } ;
64
+ use rustc_target:: abi:: { FieldIdx , Integer , VariantIdx , FIRST_VARIANT } ;
65
65
66
66
use self :: Constructor :: * ;
67
67
use self :: SliceKind :: * ;
@@ -86,35 +86,6 @@ fn expand_or_pat<'p, 'tcx>(pat: &'p Pat<'tcx>) -> Vec<&'p Pat<'tcx>> {
86
86
pats
87
87
}
88
88
89
- /// Evaluate an int constant, with a faster branch for a common case.
90
- #[ inline]
91
- fn fast_try_eval_bits < ' tcx > (
92
- tcx : TyCtxt < ' tcx > ,
93
- param_env : ty:: ParamEnv < ' tcx > ,
94
- value : & mir:: Const < ' tcx > ,
95
- ) -> Option < u128 > {
96
- let int = match value {
97
- // If the constant is already evaluated, we shortcut here.
98
- mir:: Const :: Ty ( c) if let ty:: ConstKind :: Value ( valtree) = c. kind ( ) => {
99
- valtree. unwrap_leaf ( )
100
- } ,
101
- // This is a more general form of the previous case.
102
- _ => {
103
- value. try_eval_scalar_int ( tcx, param_env) ?
104
- } ,
105
- } ;
106
- let size = match value. ty ( ) . kind ( ) {
107
- ty:: Bool => Size :: from_bytes ( 1 ) ,
108
- ty:: Char => Size :: from_bytes ( 4 ) ,
109
- ty:: Int ( ity) => Integer :: from_int_ty ( & tcx, * ity) . size ( ) ,
110
- ty:: Uint ( uty) => Integer :: from_uint_ty ( & tcx, * uty) . size ( ) ,
111
- ty:: Float ( ty:: FloatTy :: F32 ) => Primitive :: F32 . size ( & tcx) ,
112
- ty:: Float ( ty:: FloatTy :: F64 ) => Primitive :: F64 . size ( & tcx) ,
113
- _ => return None ,
114
- } ;
115
- int. to_bits ( size) . ok ( )
116
- }
117
-
118
89
/// An inclusive interval, used for precise integer exhaustiveness checking.
119
90
/// `IntRange`s always store a contiguous range. This means that values are
120
91
/// encoded such that `0` encodes the minimum value for the integer,
@@ -1346,14 +1317,14 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1346
1317
PatKind :: Constant { value } => {
1347
1318
match pat. ty . kind ( ) {
1348
1319
ty:: Bool | ty:: Char | ty:: Int ( _) | ty:: Uint ( _) => {
1349
- ctor = match fast_try_eval_bits ( cx. tcx , cx. param_env , value ) {
1320
+ ctor = match value . try_eval_bits ( cx. tcx , cx. param_env ) {
1350
1321
Some ( bits) => IntRange ( IntRange :: from_bits ( cx. tcx , pat. ty , bits) ) ,
1351
1322
None => Opaque ,
1352
1323
} ;
1353
1324
fields = Fields :: empty ( ) ;
1354
1325
}
1355
1326
ty:: Float ( ty:: FloatTy :: F32 ) => {
1356
- ctor = match fast_try_eval_bits ( cx. tcx , cx. param_env , value ) {
1327
+ ctor = match value . try_eval_bits ( cx. tcx , cx. param_env ) {
1357
1328
Some ( bits) => {
1358
1329
use rustc_apfloat:: Float ;
1359
1330
let value = rustc_apfloat:: ieee:: Single :: from_bits ( bits) ;
@@ -1364,7 +1335,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1364
1335
fields = Fields :: empty ( ) ;
1365
1336
}
1366
1337
ty:: Float ( ty:: FloatTy :: F64 ) => {
1367
- ctor = match fast_try_eval_bits ( cx. tcx , cx. param_env , value ) {
1338
+ ctor = match value . try_eval_bits ( cx. tcx , cx. param_env ) {
1368
1339
Some ( bits) => {
1369
1340
use rustc_apfloat:: Float ;
1370
1341
let value = rustc_apfloat:: ieee:: Double :: from_bits ( bits) ;
@@ -1399,8 +1370,8 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1399
1370
PatKind :: Range ( box PatRange { lo, hi, end } ) => {
1400
1371
use rustc_apfloat:: Float ;
1401
1372
let ty = lo. ty ( ) ;
1402
- let lo = fast_try_eval_bits ( cx. tcx , cx. param_env , lo ) . unwrap ( ) ;
1403
- let hi = fast_try_eval_bits ( cx. tcx , cx. param_env , hi ) . unwrap ( ) ;
1373
+ let lo = lo . try_eval_bits ( cx. tcx , cx. param_env ) . unwrap ( ) ;
1374
+ let hi = hi . try_eval_bits ( cx. tcx , cx. param_env ) . unwrap ( ) ;
1404
1375
ctor = match ty. kind ( ) {
1405
1376
ty:: Char | ty:: Int ( _) | ty:: Uint ( _) => {
1406
1377
IntRange ( IntRange :: from_range ( cx. tcx , lo, hi, ty, * end) )
0 commit comments