mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
remove check_raw after reducing it to one use only
This commit is contained in:
parent
e9ab099d6f
commit
1fec68277a
@ -382,19 +382,14 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn check_raw(data: u128, size: u8, target_size: Size) {
|
||||
assert_eq!(target_size.bytes(), size as u64);
|
||||
assert_ne!(size, 0, "you should never look at the bits of a ZST");
|
||||
Scalar::check_data(data, size);
|
||||
}
|
||||
|
||||
/// Do not call this method! Use either `assert_bits` or `force_bits`.
|
||||
#[inline]
|
||||
pub fn to_bits(self, target_size: Size) -> InterpResult<'tcx, u128> {
|
||||
match self {
|
||||
Scalar::Raw { data, size } => {
|
||||
Self::check_raw(data, size, target_size);
|
||||
assert_eq!(target_size.bytes(), size as u64);
|
||||
assert_ne!(size, 0, "you should never look at the bits of a ZST");
|
||||
Scalar::check_data(data, size);
|
||||
Ok(data)
|
||||
}
|
||||
Scalar::Ptr(_) => throw_unsup!(ReadPointerAsBytes),
|
||||
|
@ -1396,21 +1396,19 @@ impl<'tcx> IntRange<'tcx> {
|
||||
) -> Option<IntRange<'tcx>> {
|
||||
if let Some((target_size, bias)) = Self::integral_size_and_signed_bias(tcx, value.ty) {
|
||||
let ty = value.ty;
|
||||
let val = if let ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, size })) =
|
||||
value.val
|
||||
{
|
||||
// For this specific pattern we can skip a lot of effort and go
|
||||
// straight to the result, after doing a bit of checking. (We
|
||||
// could remove this branch and just use the next branch, which
|
||||
// is more general but much slower.)
|
||||
Scalar::<()>::check_raw(data, size, target_size);
|
||||
data
|
||||
} else if let Some(val) = value.try_eval_bits(tcx, param_env, ty) {
|
||||
// This is a more general form of the previous branch.
|
||||
val
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let val = (|| {
|
||||
if let ty::ConstKind::Value(ConstValue::Scalar(scalar)) = value.val {
|
||||
// For this specific pattern we can skip a lot of effort and go
|
||||
// straight to the result, after doing a bit of checking. (We
|
||||
// could remove this branch and just fall through, which
|
||||
// is more general but much slower.)
|
||||
if let Ok(bits) = scalar.to_bits_or_ptr(target_size, &tcx) {
|
||||
return Some(bits);
|
||||
}
|
||||
}
|
||||
// This is a more general form of the previous case.
|
||||
value.try_eval_bits(tcx, param_env, ty)
|
||||
})()?;
|
||||
let val = val ^ bias;
|
||||
Some(IntRange { range: val..=val, ty, span })
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user