teach clippy about IeeeFloat, and make all 'allow' into 'expect'
This commit is contained in:
parent
3253cc6785
commit
c1b8d6611e
@ -1 +1 @@
|
||||
arithmetic-side-effects-allowed = ["rustc_abi::Size"]
|
||||
arithmetic-side-effects-allowed = ["rustc_abi::Size", "rustc_apfloat::ieee::IeeeFloat"]
|
||||
|
@ -354,7 +354,7 @@ impl<'tcx> Stack {
|
||||
self.borrows.get(idx).cloned()
|
||||
}
|
||||
|
||||
#[allow(clippy::len_without_is_empty)] // Stacks are never empty
|
||||
#[expect(clippy::len_without_is_empty)] // Stacks are never empty
|
||||
pub fn len(&self) -> usize {
|
||||
self.borrows.len()
|
||||
}
|
||||
|
@ -300,7 +300,6 @@ impl<'tcx> StoreBuffer {
|
||||
interp_ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::if_same_then_else, clippy::needless_bool)]
|
||||
/// Selects a valid store element in the buffer.
|
||||
fn fetch_store<R: rand::Rng + ?Sized>(
|
||||
&self,
|
||||
|
@ -423,7 +423,7 @@ pub fn create_ecx<'tcx>(
|
||||
/// Evaluates the entry function specified by `entry_id`.
|
||||
/// Returns `Some(return_code)` if program executed completed.
|
||||
/// Returns `None` if an evaluation error occurred.
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
#[expect(clippy::needless_lifetimes)]
|
||||
pub fn eval_entry<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
entry_id: DefId,
|
||||
|
@ -156,7 +156,7 @@ pub fn iter_exported_symbols<'tcx>(
|
||||
for cnum in dependency_format.1.iter().enumerate().filter_map(|(num, &linkage)| {
|
||||
// We add 1 to the number because that's what rustc also does everywhere it
|
||||
// calls `CrateNum::new`...
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
(linkage != Linkage::NotLinked).then_some(CrateNum::new(num + 1))
|
||||
}) {
|
||||
// We can ignore `_export_info` here: we are a Rust crate, and everything is exported
|
||||
|
@ -292,7 +292,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
let b = this.read_scalar(b)?.to_f32()?;
|
||||
let c = this.read_scalar(c)?.to_f32()?;
|
||||
let fuse: bool = this.machine.rng.get_mut().gen();
|
||||
#[allow(clippy::arithmetic_side_effects)] // float ops don't overflow
|
||||
let res = if fuse {
|
||||
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
|
||||
a.to_host().mul_add(b.to_host(), c.to_host()).to_soft()
|
||||
@ -308,7 +307,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
let b = this.read_scalar(b)?.to_f64()?;
|
||||
let c = this.read_scalar(c)?.to_f64()?;
|
||||
let fuse: bool = this.machine.rng.get_mut().gen();
|
||||
#[allow(clippy::arithmetic_side_effects)] // float ops don't overflow
|
||||
let res = if fuse {
|
||||
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
|
||||
a.to_host().mul_add(b.to_host(), c.to_host()).to_soft()
|
||||
|
@ -750,7 +750,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
|
||||
let val = if simd_element_to_bool(mask)? {
|
||||
// Size * u64 is implemented as always checked
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
let ptr = ptr.wrapping_offset(dest.layout.size * i, this);
|
||||
let place = this.ptr_to_mplace(ptr, dest.layout);
|
||||
this.read_immediate(&place)?
|
||||
@ -774,7 +773,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
|
||||
if simd_element_to_bool(mask)? {
|
||||
// Size * u64 is implemented as always checked
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
let ptr = ptr.wrapping_offset(val.layout.size * i, this);
|
||||
let place = this.ptr_to_mplace(ptr, val.layout);
|
||||
this.write_immediate(*val, &place)?
|
||||
@ -831,7 +829,7 @@ fn simd_bitmask_index(idx: u32, vec_len: u32, endianness: Endian) -> u32 {
|
||||
assert!(idx < vec_len);
|
||||
match endianness {
|
||||
Endian::Little => idx,
|
||||
#[allow(clippy::arithmetic_side_effects)] // idx < vec_len
|
||||
#[expect(clippy::arithmetic_side_effects)] // idx < vec_len
|
||||
Endian::Big => vec_len - 1 - idx, // reverse order of bits
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ use crate::*;
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct DynSym(Symbol);
|
||||
|
||||
#[allow(clippy::should_implement_trait)]
|
||||
#[expect(clippy::should_implement_trait)]
|
||||
impl DynSym {
|
||||
pub fn from_str(name: &str) -> Self {
|
||||
DynSym(Symbol::intern(name))
|
||||
@ -648,7 +648,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
let val = this.read_scalar(val)?.to_i32()?;
|
||||
let num = this.read_target_usize(num)?;
|
||||
// The docs say val is "interpreted as unsigned char".
|
||||
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||
#[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||
let val = val as u8;
|
||||
|
||||
// C requires that this must always be a valid pointer (C18 §7.1.4).
|
||||
@ -661,7 +661,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
.position(|&c| c == val)
|
||||
{
|
||||
let idx = u64::try_from(idx).unwrap();
|
||||
#[allow(clippy::arithmetic_side_effects)] // idx < num, so this never wraps
|
||||
#[expect(clippy::arithmetic_side_effects)] // idx < num, so this never wraps
|
||||
let new_ptr = ptr.wrapping_offset(Size::from_bytes(num - idx - 1), this);
|
||||
this.write_pointer(new_ptr, dest)?;
|
||||
} else {
|
||||
@ -675,7 +675,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
let val = this.read_scalar(val)?.to_i32()?;
|
||||
let num = this.read_target_usize(num)?;
|
||||
// The docs say val is "interpreted as unsigned char".
|
||||
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||
#[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||
let val = val as u8;
|
||||
|
||||
// C requires that this must always be a valid pointer (C18 §7.1.4).
|
||||
|
@ -188,7 +188,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
}
|
||||
|
||||
/// The inverse of `io_error_to_errnum`.
|
||||
#[allow(clippy::needless_return)]
|
||||
#[expect(clippy::needless_return)]
|
||||
fn try_errnum_to_io_error(
|
||||
&self,
|
||||
errnum: Scalar,
|
||||
|
@ -53,7 +53,7 @@ impl<'tcx> Default for TlsData<'tcx> {
|
||||
impl<'tcx> TlsData<'tcx> {
|
||||
/// Generate a new TLS key with the given destructor.
|
||||
/// `max_size` determines the integer size the key has to fit in.
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
pub fn create_tls_key(
|
||||
&mut self,
|
||||
dtor: Option<ty::Instance<'tcx>>,
|
||||
|
@ -385,7 +385,7 @@ pub struct DirTable {
|
||||
}
|
||||
|
||||
impl DirTable {
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
fn insert_new(&mut self, read_dir: ReadDir) -> u64 {
|
||||
let id = self.next_id;
|
||||
self.next_id += 1;
|
||||
|
@ -22,7 +22,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
let flags = this.read_scalar(flags)?.to_i32()?;
|
||||
|
||||
// old_address must be a multiple of the page size
|
||||
#[allow(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero
|
||||
#[expect(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero
|
||||
if old_address.addr().bytes() % this.machine.page_size != 0 || new_size == 0 {
|
||||
this.set_last_error(LibcError("EINVAL"))?;
|
||||
return interp_ok(this.eval_libc("MAP_FAILED"));
|
||||
|
@ -182,7 +182,7 @@ pub fn futex<'tcx>(
|
||||
// before doing the syscall.
|
||||
this.atomic_fence(AtomicFenceOrd::SeqCst)?;
|
||||
let mut n = 0;
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
for _ in 0..val {
|
||||
if this.futex_wake(addr_usize, bitset)? {
|
||||
n += 1;
|
||||
|
@ -132,7 +132,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
|
||||
// addr must be a multiple of the page size, but apart from that munmap is just implemented
|
||||
// as a dealloc.
|
||||
#[allow(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero
|
||||
#[expect(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero
|
||||
if addr.addr().bytes() % this.machine.page_size != 0 {
|
||||
return this.set_last_error_and_return_i32(LibcError("EINVAL"));
|
||||
}
|
||||
|
@ -685,7 +685,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
|
||||
let id = rwlock_get_data(this, rwlock_op)?.id;
|
||||
|
||||
#[allow(clippy::if_same_then_else)]
|
||||
if this.rwlock_reader_unlock(id)? || this.rwlock_writer_unlock(id)? {
|
||||
interp_ok(())
|
||||
} else {
|
||||
|
@ -25,7 +25,7 @@ fn win_absolute<'tcx>(path: &Path) -> InterpResult<'tcx, io::Result<PathBuf>> {
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[allow(clippy::get_first, clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::get_first, clippy::arithmetic_side_effects)]
|
||||
fn win_absolute<'tcx>(path: &Path) -> InterpResult<'tcx, io::Result<PathBuf>> {
|
||||
// We are on Unix, so we need to implement parts of the logic ourselves.
|
||||
let bytes = path.as_os_str().as_encoded_bytes();
|
||||
|
@ -63,7 +63,7 @@ impl Handle {
|
||||
let floor_log2 = variant_count.ilog2();
|
||||
|
||||
// we need to add one for non powers of two to compensate for the difference
|
||||
#[allow(clippy::arithmetic_side_effects)] // cannot overflow
|
||||
#[expect(clippy::arithmetic_side_effects)] // cannot overflow
|
||||
if variant_count.is_power_of_two() { floor_log2 } else { floor_log2 + 1 }
|
||||
}
|
||||
|
||||
@ -88,8 +88,7 @@ impl Handle {
|
||||
|
||||
// packs the data into the lower `data_size` bits
|
||||
// and packs the discriminant right above the data
|
||||
#[allow(clippy::arithmetic_side_effects)] // cannot overflow
|
||||
return discriminant << data_size | data;
|
||||
discriminant << data_size | data
|
||||
}
|
||||
|
||||
fn new(discriminant: u32, data: u32) -> Option<Self> {
|
||||
@ -107,11 +106,10 @@ impl Handle {
|
||||
let data_size = u32::BITS.strict_sub(disc_size);
|
||||
|
||||
// the lower `data_size` bits of this mask are 1
|
||||
#[allow(clippy::arithmetic_side_effects)] // cannot overflow
|
||||
#[expect(clippy::arithmetic_side_effects)] // cannot overflow
|
||||
let data_mask = 2u32.pow(data_size) - 1;
|
||||
|
||||
// the discriminant is stored right above the lower `data_size` bits
|
||||
#[allow(clippy::arithmetic_side_effects)] // cannot overflow
|
||||
let discriminant = handle >> data_size;
|
||||
|
||||
// the data is stored in the lower `data_size` bits
|
||||
@ -123,7 +121,7 @@ impl Handle {
|
||||
pub fn to_scalar(self, cx: &impl HasDataLayout) -> Scalar {
|
||||
// 64-bit handles are sign extended 32-bit handles
|
||||
// see https://docs.microsoft.com/en-us/windows/win32/winprog64/interprocess-communication
|
||||
#[allow(clippy::cast_possible_wrap)] // we want it to wrap
|
||||
#[expect(clippy::cast_possible_wrap)] // we want it to wrap
|
||||
let signed_handle = self.to_packed() as i32;
|
||||
Scalar::from_target_isize(signed_handle.into(), cx)
|
||||
}
|
||||
@ -134,7 +132,7 @@ impl Handle {
|
||||
) -> InterpResult<'tcx, Option<Self>> {
|
||||
let sign_extended_handle = handle.to_target_isize(cx)?;
|
||||
|
||||
#[allow(clippy::cast_sign_loss)] // we want to lose the sign
|
||||
#[expect(clippy::cast_sign_loss)] // we want to lose the sign
|
||||
let handle = if let Ok(signed_handle) = i32::try_from(sign_extended_handle) {
|
||||
signed_handle as u32
|
||||
} else {
|
||||
|
@ -136,7 +136,7 @@ fn affine_transform<'tcx>(
|
||||
// This is a evaluated at compile time. Trait based conversion is not available.
|
||||
/// See <https://www.corsix.org/content/galois-field-instructions-2021-cpus> for the
|
||||
/// definition of `gf_inv` which was used for the creation of this table.
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
#[expect(clippy::cast_possible_truncation)]
|
||||
static TABLE: [u8; 256] = {
|
||||
let mut array = [0; 256];
|
||||
|
||||
@ -163,7 +163,7 @@ static TABLE: [u8; 256] = {
|
||||
/// polynomial representation with the reduction polynomial x^8 + x^4 + x^3 + x + 1.
|
||||
/// See <https://www.corsix.org/content/galois-field-instructions-2021-cpus> for details.
|
||||
// This is a const function. Trait based conversion is not available.
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
#[expect(clippy::cast_possible_truncation)]
|
||||
const fn gf2p8_mul(left: u8, right: u8) -> u8 {
|
||||
// This implementation is based on the `gf2p8mul_byte` definition found inside the Intel intrinsics guide.
|
||||
// See https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=gf2p8mul
|
||||
|
@ -397,7 +397,6 @@ enum FloatUnaryOp {
|
||||
}
|
||||
|
||||
/// Performs `which` scalar operation on `op` and returns the result.
|
||||
#[allow(clippy::arithmetic_side_effects)] // floating point operations without side effects
|
||||
fn unary_op_f32<'tcx>(
|
||||
this: &mut crate::MiriInterpCx<'tcx>,
|
||||
which: FloatUnaryOp,
|
||||
@ -426,7 +425,7 @@ fn unary_op_f32<'tcx>(
|
||||
}
|
||||
|
||||
/// Disturbes a floating-point result by a relative error on the order of (-2^scale, 2^scale).
|
||||
#[allow(clippy::arithmetic_side_effects)] // floating point arithmetic cannot panic
|
||||
#[expect(clippy::arithmetic_side_effects)] // floating point arithmetic cannot panic
|
||||
fn apply_random_float_error<F: rustc_apfloat::Float>(
|
||||
this: &mut crate::MiriInterpCx<'_>,
|
||||
val: F,
|
||||
@ -1000,7 +999,6 @@ fn mask_load<'tcx>(
|
||||
let dest = this.project_index(&dest, i)?;
|
||||
|
||||
if this.read_scalar(&mask)?.to_uint(mask_item_size)? >> high_bit_offset != 0 {
|
||||
#[allow(clippy::arithmetic_side_effects)] // `Size` arithmetic is checked
|
||||
let ptr = ptr.wrapping_offset(dest.layout.size * i, &this.tcx);
|
||||
// Unaligned copy, which is what we want.
|
||||
this.mem_copy(ptr, dest.ptr(), dest.layout.size, /*nonoverlapping*/ true)?;
|
||||
@ -1036,7 +1034,6 @@ fn mask_store<'tcx>(
|
||||
if this.read_scalar(&mask)?.to_uint(mask_item_size)? >> high_bit_offset != 0 {
|
||||
// *Non-inbounds* pointer arithmetic to compute the destination.
|
||||
// (That's why we can't use a place projection.)
|
||||
#[allow(clippy::arithmetic_side_effects)] // `Size` arithmetic is checked
|
||||
let ptr = ptr.wrapping_offset(value.layout.size * i, &this.tcx);
|
||||
// Deref the pointer *unaligned*, and do the copy.
|
||||
let dest = this.ptr_to_mplace_unaligned(ptr, value.layout);
|
||||
@ -1135,7 +1132,7 @@ fn pmulhrsw<'tcx>(
|
||||
|
||||
// The result of this operation can overflow a signed 16-bit integer.
|
||||
// When `left` and `right` are -0x8000, the result is 0x8000.
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
#[expect(clippy::cast_possible_truncation)]
|
||||
let res = res as i16;
|
||||
|
||||
this.write_scalar(Scalar::from_i16(res), &dest)?;
|
||||
|
@ -68,7 +68,7 @@ const USE_SIGNED: u8 = 2;
|
||||
/// The mask may be negated if negation flags inside the immediate byte are set.
|
||||
///
|
||||
/// For more information, see the Intel Software Developer's Manual, Vol. 2b, Chapter 4.1.
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
#[expect(clippy::arithmetic_side_effects)]
|
||||
fn compare_strings<'tcx>(
|
||||
this: &mut MiriInterpCx<'tcx>,
|
||||
str1: &OpTy<'tcx>,
|
||||
@ -444,7 +444,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
||||
let crc = if bit_size == 64 {
|
||||
// The 64-bit version will only consider the lower 32 bits,
|
||||
// while the upper 32 bits get discarded.
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
#[expect(clippy::cast_possible_truncation)]
|
||||
u128::from((left.to_u64()? as u32).reverse_bits())
|
||||
} else {
|
||||
u128::from(left.to_u32()?.reverse_bits())
|
||||
|
@ -181,7 +181,7 @@ unsafe fn schedule(v0: __m128i, v1: __m128i, v2: __m128i, v3: __m128i) -> __m128
|
||||
}
|
||||
|
||||
// we use unaligned loads with `__m128i` pointers
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
#[expect(clippy::cast_ptr_alignment)]
|
||||
#[target_feature(enable = "sha,sse2,ssse3,sse4.1")]
|
||||
unsafe fn digest_blocks(state: &mut [u32; 8], blocks: &[[u8; 64]]) {
|
||||
#[allow(non_snake_case)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user