@@ -228,7 +228,7 @@ impl LiteralExpander<'tcx> {
228
228
ConstValue :: Slice {
229
229
data : self . tcx . alloc_map . lock ( ) . unwrap_memory ( p. alloc_id ) ,
230
230
start : p. offset . bytes ( ) . try_into ( ) . unwrap ( ) ,
231
- end : n. unwrap_usize ( self . tcx ) . try_into ( ) . unwrap ( ) ,
231
+ end : n. eval_usize ( self . tcx ) . try_into ( ) . unwrap ( ) ,
232
232
}
233
233
} ,
234
234
// fat pointers stay the same
@@ -646,8 +646,8 @@ fn all_constructors<'a, 'tcx>(
646
646
ConstantValue ( ty:: Const :: from_bool ( cx. tcx , b) )
647
647
} ) . collect ( )
648
648
}
649
- ty:: Array ( ref sub_ty, len) if len. assert_usize ( cx. tcx ) . is_some ( ) => {
650
- let len = len. unwrap_usize ( cx. tcx ) ;
649
+ ty:: Array ( ref sub_ty, len) if len. try_eval_usize ( cx. tcx ) . is_some ( ) => {
650
+ let len = len. eval_usize ( cx. tcx ) ;
651
651
if len != 0 && cx. is_uninhabited ( sub_ty) {
652
652
vec ! [ ]
653
653
} else {
@@ -789,7 +789,7 @@ where
789
789
match ( value. val , & value. ty . sty ) {
790
790
( _, ty:: Array ( _, n) ) => max_fixed_len = cmp:: max (
791
791
max_fixed_len,
792
- n. unwrap_usize ( cx. tcx ) ,
792
+ n. eval_usize ( cx. tcx ) ,
793
793
) ,
794
794
( ConstValue :: Slice { start, end, .. } , ty:: Slice ( _) ) => max_fixed_len = cmp:: max (
795
795
max_fixed_len,
@@ -856,7 +856,7 @@ impl<'tcx> IntRange<'tcx> {
856
856
}
857
857
ConstantValue ( val) if is_integral ( val. ty ) => {
858
858
let ty = val. ty ;
859
- if let Some ( val) = val. assert_bits ( tcx, ty) {
859
+ if let Some ( val) = val. try_eval_bits ( tcx, ty) {
860
860
let bias = IntRange :: signed_bias ( tcx, ty) ;
861
861
let val = val ^ bias;
862
862
Some ( IntRange { range : val..=val, ty } )
@@ -873,8 +873,8 @@ impl<'tcx> IntRange<'tcx> {
873
873
match pat. kind {
874
874
box PatternKind :: Constant { value } => break ConstantValue ( value) ,
875
875
box PatternKind :: Range ( PatternRange { lo, hi, ty, end } ) => break ConstantRange (
876
- lo. unwrap_bits ( tcx, ty) ,
877
- hi. unwrap_bits ( tcx, ty) ,
876
+ lo. eval_bits ( tcx, ty) ,
877
+ hi. eval_bits ( tcx, ty) ,
878
878
ty,
879
879
end,
880
880
) ,
@@ -1327,14 +1327,14 @@ fn pat_constructors<'tcx>(cx: &mut MatchCheckCtxt<'_, 'tcx>,
1327
1327
PatternKind :: Constant { value } => Some ( vec ! [ ConstantValue ( value) ] ) ,
1328
1328
PatternKind :: Range ( PatternRange { lo, hi, ty, end } ) =>
1329
1329
Some ( vec ! [ ConstantRange (
1330
- lo. unwrap_bits ( cx. tcx, ty) ,
1331
- hi. unwrap_bits ( cx. tcx, ty) ,
1330
+ lo. eval_bits ( cx. tcx, ty) ,
1331
+ hi. eval_bits ( cx. tcx, ty) ,
1332
1332
ty,
1333
1333
end,
1334
1334
) ] ) ,
1335
1335
PatternKind :: Array { .. } => match pcx. ty . sty {
1336
1336
ty:: Array ( _, length) => Some ( vec ! [
1337
- Slice ( length. unwrap_usize ( cx. tcx) )
1337
+ Slice ( length. eval_usize ( cx. tcx) )
1338
1338
] ) ,
1339
1339
_ => span_bug ! ( pat. span, "bad ty {:?} for array pattern" , pcx. ty)
1340
1340
} ,
@@ -1402,7 +1402,7 @@ fn constructor_sub_pattern_tys<'a, 'tcx>(
1402
1402
match ty. sty {
1403
1403
// If the field type returned is an array of an unknown
1404
1404
// size return an TyErr.
1405
- ty:: Array ( _, len) if len. assert_usize ( cx. tcx ) . is_none ( ) =>
1405
+ ty:: Array ( _, len) if len. try_eval_usize ( cx. tcx ) . is_none ( ) =>
1406
1406
cx. tcx . types . err ,
1407
1407
_ => ty,
1408
1408
}
@@ -1436,7 +1436,7 @@ fn slice_pat_covered_by_const<'tcx>(
1436
1436
let data: & [ u8 ] = match ( const_val. val , & const_val. ty . sty ) {
1437
1437
( ConstValue :: ByRef { offset, alloc, .. } , ty:: Array ( t, n) ) => {
1438
1438
assert_eq ! ( * t, tcx. types. u8 ) ;
1439
- let n = n. assert_usize ( tcx) . unwrap ( ) ;
1439
+ let n = n. eval_usize ( tcx) ;
1440
1440
let ptr = Pointer :: new ( AllocId ( 0 ) , offset) ;
1441
1441
alloc. get_bytes ( & tcx, ptr, Size :: from_bytes ( n) ) . unwrap ( )
1442
1442
} ,
@@ -1464,7 +1464,7 @@ fn slice_pat_covered_by_const<'tcx>(
1464
1464
{
1465
1465
match pat. kind {
1466
1466
box PatternKind :: Constant { value } => {
1467
- let b = value. unwrap_bits ( tcx, pat. ty ) ;
1467
+ let b = value. eval_bits ( tcx, pat. ty ) ;
1468
1468
assert_eq ! ( b as u8 as u128 , b) ;
1469
1469
if b as u8 != * ch {
1470
1470
return Ok ( false ) ;
@@ -1760,7 +1760,7 @@ fn specialize<'p, 'a: 'p, 'tcx>(
1760
1760
ConstValue :: ByRef { offset, alloc, .. } => (
1761
1761
alloc,
1762
1762
offset,
1763
- n. unwrap_usize ( cx. tcx ) ,
1763
+ n. eval_usize ( cx. tcx ) ,
1764
1764
t,
1765
1765
) ,
1766
1766
_ => span_bug ! (
0 commit comments