Skip to content

Commit 1fec682

Browse files
committed
remove check_raw after reducing it to one use only
1 parent e9ab099 commit 1fec682

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

src/librustc/mir/interpret/value.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,19 +382,14 @@ impl<'tcx, Tag> Scalar<Tag> {
382382
}
383383
}
384384

385-
#[inline(always)]
386-
pub fn check_raw(data: u128, size: u8, target_size: Size) {
387-
assert_eq!(target_size.bytes(), size as u64);
388-
assert_ne!(size, 0, "you should never look at the bits of a ZST");
389-
Scalar::check_data(data, size);
390-
}
391-
392385
/// Do not call this method! Use either `assert_bits` or `force_bits`.
393386
#[inline]
394387
pub fn to_bits(self, target_size: Size) -> InterpResult<'tcx, u128> {
395388
match self {
396389
Scalar::Raw { data, size } => {
397-
Self::check_raw(data, size, target_size);
390+
assert_eq!(target_size.bytes(), size as u64);
391+
assert_ne!(size, 0, "you should never look at the bits of a ZST");
392+
Scalar::check_data(data, size);
398393
Ok(data)
399394
}
400395
Scalar::Ptr(_) => throw_unsup!(ReadPointerAsBytes),

src/librustc_mir_build/hair/pattern/_match.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,21 +1396,19 @@ impl<'tcx> IntRange<'tcx> {
13961396
) -> Option<IntRange<'tcx>> {
13971397
if let Some((target_size, bias)) = Self::integral_size_and_signed_bias(tcx, value.ty) {
13981398
let ty = value.ty;
1399-
let val = if let ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, size })) =
1400-
value.val
1401-
{
1402-
// For this specific pattern we can skip a lot of effort and go
1403-
// straight to the result, after doing a bit of checking. (We
1404-
// could remove this branch and just use the next branch, which
1405-
// is more general but much slower.)
1406-
Scalar::<()>::check_raw(data, size, target_size);
1407-
data
1408-
} else if let Some(val) = value.try_eval_bits(tcx, param_env, ty) {
1409-
// This is a more general form of the previous branch.
1410-
val
1411-
} else {
1412-
return None;
1413-
};
1399+
let val = (|| {
1400+
if let ty::ConstKind::Value(ConstValue::Scalar(scalar)) = value.val {
1401+
// For this specific pattern we can skip a lot of effort and go
1402+
// straight to the result, after doing a bit of checking. (We
1403+
// could remove this branch and just fall through, which
1404+
// is more general but much slower.)
1405+
if let Ok(bits) = scalar.to_bits_or_ptr(target_size, &tcx) {
1406+
return Some(bits);
1407+
}
1408+
}
1409+
// This is a more general form of the previous case.
1410+
value.try_eval_bits(tcx, param_env, ty)
1411+
})()?;
14141412
let val = val ^ bias;
14151413
Some(IntRange { range: val..=val, ty, span })
14161414
} else {

0 commit comments

Comments
 (0)