@@ -1387,63 +1387,48 @@ fn all_constructors<'a, 'tcx>(
1387
1387
. map ( |v| Variant ( v. def_id ) )
1388
1388
. collect ( ) ,
1389
1389
ty:: Char => {
1390
- let param_env = ty:: ParamEnv :: empty ( ) . and ( cx. tcx . types . char ) ;
1391
- let to_const = |x| ty:: Const :: from_bits ( cx. tcx , x as u128 , param_env) ;
1390
+ let to_const = |x| x;
1392
1391
vec ! [
1393
1392
// The valid Unicode Scalar Value ranges.
1394
1393
IntRange (
1395
1394
IntRange :: from_range(
1396
1395
cx. tcx,
1397
- cx. param_env ,
1398
- to_const( '\u{0000}' ) ,
1399
- to_const( '\u{D7FF}' ) ,
1400
- & RangeEnd :: Included ,
1396
+ cx. tcx . types . char ,
1397
+ to_const( '\u{0000}' as u128 ) ,
1398
+ to_const( '\u{D7FF}' as u128 ) ,
1399
+ RangeEnd :: Included ,
1401
1400
)
1402
1401
. unwrap( ) ,
1403
1402
) ,
1404
1403
IntRange (
1405
1404
IntRange :: from_range(
1406
1405
cx. tcx,
1407
- cx. param_env ,
1408
- to_const( '\u{E000}' ) ,
1409
- to_const( '\u{10FFFF}' ) ,
1410
- & RangeEnd :: Included ,
1406
+ cx. tcx . types . char ,
1407
+ to_const( '\u{E000}' as u128 ) ,
1408
+ to_const( '\u{10FFFF}' as u128 ) ,
1409
+ RangeEnd :: Included ,
1411
1410
)
1412
1411
. unwrap( ) ,
1413
1412
) ,
1414
1413
]
1415
1414
}
1416
1415
ty:: Int ( ity) => {
1417
- let param_env = ty:: ParamEnv :: empty ( ) . and ( ty) ;
1418
- let to_const = |x| ty:: Const :: from_bits ( cx. tcx , x, param_env) ;
1416
+ let to_const = |x| x;
1419
1417
let bits = Integer :: from_attr ( & cx. tcx , SignedInt ( ity) ) . size ( ) . bits ( ) as u128 ;
1420
1418
let min = 1u128 << ( bits - 1 ) ;
1421
1419
let max = min - 1 ;
1422
1420
vec ! [ IntRange (
1423
- IntRange :: from_range(
1424
- cx. tcx,
1425
- cx. param_env,
1426
- to_const( min) ,
1427
- to_const( max) ,
1428
- & RangeEnd :: Included ,
1429
- )
1430
- . unwrap( ) ,
1421
+ IntRange :: from_range( cx. tcx, ty, to_const( min) , to_const( max) , RangeEnd :: Included )
1422
+ . unwrap( ) ,
1431
1423
) ]
1432
1424
}
1433
1425
ty:: Uint ( uty) => {
1434
- let param_env = ty:: ParamEnv :: empty ( ) . and ( ty) ;
1435
- let to_const = |x| ty:: Const :: from_bits ( cx. tcx , x, param_env) ;
1426
+ let to_const = |x| x;
1436
1427
let size = Integer :: from_attr ( & cx. tcx , UnsignedInt ( uty) ) . size ( ) ;
1437
1428
let max = truncate ( u128:: max_value ( ) , size) ;
1438
1429
vec ! [ IntRange (
1439
- IntRange :: from_range(
1440
- cx. tcx,
1441
- cx. param_env,
1442
- to_const( 0 ) ,
1443
- to_const( max) ,
1444
- & RangeEnd :: Included ,
1445
- )
1446
- . unwrap( ) ,
1430
+ IntRange :: from_range( cx. tcx, ty, to_const( 0 ) , to_const( max) , RangeEnd :: Included )
1431
+ . unwrap( ) ,
1447
1432
) ]
1448
1433
}
1449
1434
_ => {
@@ -1535,7 +1520,7 @@ impl<'tcx> IntRange<'tcx> {
1535
1520
}
1536
1521
1537
1522
#[ inline]
1538
- fn from_range (
1523
+ fn from_const_range (
1539
1524
tcx : TyCtxt < ' tcx > ,
1540
1525
param_env : ty:: ParamEnv < ' tcx > ,
1541
1526
lo : & Const < ' tcx > ,
@@ -1545,16 +1530,27 @@ impl<'tcx> IntRange<'tcx> {
1545
1530
let ty = lo. ty ;
1546
1531
let lo = lo. eval_bits ( tcx, param_env, lo. ty ) ;
1547
1532
let hi = hi. eval_bits ( tcx, param_env, hi. ty ) ;
1533
+ Self :: from_range ( tcx, ty, lo, hi, * end)
1534
+ }
1535
+
1536
+ #[ inline]
1537
+ fn from_range (
1538
+ tcx : TyCtxt < ' tcx > ,
1539
+ ty : Ty < ' tcx > ,
1540
+ lo : u128 ,
1541
+ hi : u128 ,
1542
+ end : RangeEnd ,
1543
+ ) -> Option < IntRange < ' tcx > > {
1548
1544
if Self :: is_integral ( ty) {
1549
1545
// Perform a shift if the underlying types are signed,
1550
1546
// which makes the interval arithmetic simpler.
1551
1547
let bias = IntRange :: signed_bias ( tcx, ty) ;
1552
1548
let ( lo, hi) = ( lo ^ bias, hi ^ bias) ;
1553
1549
// Make sure the interval is well-formed.
1554
- if lo > hi || lo == hi && * end == RangeEnd :: Excluded {
1550
+ if lo > hi || lo == hi && end == RangeEnd :: Excluded {
1555
1551
None
1556
1552
} else {
1557
- let offset = ( * end == RangeEnd :: Excluded ) as u128 ;
1553
+ let offset = ( end == RangeEnd :: Excluded ) as u128 ;
1558
1554
Some ( IntRange { range : lo..=( hi - offset) , ty } )
1559
1555
}
1560
1556
} else {
@@ -1851,7 +1847,7 @@ fn pat_constructors<'tcx>(
1851
1847
}
1852
1848
}
1853
1849
PatKind :: Range ( PatRange { lo, hi, end } ) => {
1854
- if let Some ( range) = IntRange :: from_range ( tcx, param_env, & lo, & hi, & end) {
1850
+ if let Some ( range) = IntRange :: from_const_range ( tcx, param_env, & lo, & hi, & end) {
1855
1851
smallvec ! [ IntRange ( range) ]
1856
1852
} else {
1857
1853
smallvec ! [ ConstantRange ( lo, hi, end) ]
@@ -1951,7 +1947,7 @@ fn constructor_intersects_pattern<'p, 'tcx>(
1951
1947
let pat = match * pat. kind {
1952
1948
PatKind :: Constant { value } => IntRange :: from_const ( cx. tcx , cx. param_env , value) ?,
1953
1949
PatKind :: Range ( PatRange { lo, hi, end } ) => {
1954
- IntRange :: from_range ( cx. tcx , cx. param_env , lo, hi, & end) ?
1950
+ IntRange :: from_const_range ( cx. tcx , cx. param_env , lo, hi, & end) ?
1955
1951
}
1956
1952
_ => bug ! ( "`constructor_intersects_pattern` called with {:?}" , pat) ,
1957
1953
} ;
0 commit comments