Skip to content

Commit 907e8b8

Browse files
committed
teach clippy about IeeeFloat, and make all 'allow' into 'expect'
1 parent 89da22b commit 907e8b8

File tree

21 files changed

+28
-39
lines changed

21 files changed

+28
-39
lines changed

clippy.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
arithmetic-side-effects-allowed = ["rustc_abi::Size"]
1+
arithmetic-side-effects-allowed = ["rustc_abi::Size", "rustc_apfloat::ieee::IeeeFloat"]

src/borrow_tracker/stacked_borrows/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl<'tcx> Stack {
354354
self.borrows.get(idx).cloned()
355355
}
356356

357-
#[allow(clippy::len_without_is_empty)] // Stacks are never empty
357+
#[expect(clippy::len_without_is_empty)] // Stacks are never empty
358358
pub fn len(&self) -> usize {
359359
self.borrows.len()
360360
}

src/concurrency/weak_memory.rs

-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ impl<'tcx> StoreBuffer {
300300
interp_ok(())
301301
}
302302

303-
#[allow(clippy::if_same_then_else, clippy::needless_bool)]
304303
/// Selects a valid store element in the buffer.
305304
fn fetch_store<R: rand::Rng + ?Sized>(
306305
&self,

src/eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ pub fn create_ecx<'tcx>(
423423
/// Evaluates the entry function specified by `entry_id`.
424424
/// Returns `Some(return_code)` if program executed completed.
425425
/// Returns `None` if an evaluation error occurred.
426-
#[allow(clippy::needless_lifetimes)]
426+
#[expect(clippy::needless_lifetimes)]
427427
pub fn eval_entry<'tcx>(
428428
tcx: TyCtxt<'tcx>,
429429
entry_id: DefId,

src/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub fn iter_exported_symbols<'tcx>(
156156
for cnum in dependency_format.1.iter().enumerate().filter_map(|(num, &linkage)| {
157157
// We add 1 to the number because that's what rustc also does everywhere it
158158
// calls `CrateNum::new`...
159-
#[allow(clippy::arithmetic_side_effects)]
159+
#[expect(clippy::arithmetic_side_effects)]
160160
(linkage != Linkage::NotLinked).then_some(CrateNum::new(num + 1))
161161
}) {
162162
// We can ignore `_export_info` here: we are a Rust crate, and everything is exported

src/intrinsics/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
292292
let b = this.read_scalar(b)?.to_f32()?;
293293
let c = this.read_scalar(c)?.to_f32()?;
294294
let fuse: bool = this.machine.rng.get_mut().gen();
295-
#[allow(clippy::arithmetic_side_effects)] // float ops don't overflow
296295
let res = if fuse {
297296
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
298297
a.to_host().mul_add(b.to_host(), c.to_host()).to_soft()
@@ -308,7 +307,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
308307
let b = this.read_scalar(b)?.to_f64()?;
309308
let c = this.read_scalar(c)?.to_f64()?;
310309
let fuse: bool = this.machine.rng.get_mut().gen();
311-
#[allow(clippy::arithmetic_side_effects)] // float ops don't overflow
312310
let res = if fuse {
313311
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
314312
a.to_host().mul_add(b.to_host(), c.to_host()).to_soft()

src/intrinsics/simd.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
750750

751751
let val = if simd_element_to_bool(mask)? {
752752
// Size * u64 is implemented as always checked
753-
#[allow(clippy::arithmetic_side_effects)]
754753
let ptr = ptr.wrapping_offset(dest.layout.size * i, this);
755754
let place = this.ptr_to_mplace(ptr, dest.layout);
756755
this.read_immediate(&place)?
@@ -774,7 +773,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
774773

775774
if simd_element_to_bool(mask)? {
776775
// Size * u64 is implemented as always checked
777-
#[allow(clippy::arithmetic_side_effects)]
778776
let ptr = ptr.wrapping_offset(val.layout.size * i, this);
779777
let place = this.ptr_to_mplace(ptr, val.layout);
780778
this.write_immediate(*val, &place)?
@@ -831,7 +829,7 @@ fn simd_bitmask_index(idx: u32, vec_len: u32, endianness: Endian) -> u32 {
831829
assert!(idx < vec_len);
832830
match endianness {
833831
Endian::Little => idx,
834-
#[allow(clippy::arithmetic_side_effects)] // idx < vec_len
832+
#[expect(clippy::arithmetic_side_effects)] // idx < vec_len
835833
Endian::Big => vec_len - 1 - idx, // reverse order of bits
836834
}
837835
}

src/shims/foreign_items.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::*;
2121
#[derive(Debug, Copy, Clone)]
2222
pub struct DynSym(Symbol);
2323

24-
#[allow(clippy::should_implement_trait)]
24+
#[expect(clippy::should_implement_trait)]
2525
impl DynSym {
2626
pub fn from_str(name: &str) -> Self {
2727
DynSym(Symbol::intern(name))
@@ -648,7 +648,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
648648
let val = this.read_scalar(val)?.to_i32()?;
649649
let num = this.read_target_usize(num)?;
650650
// The docs say val is "interpreted as unsigned char".
651-
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
651+
#[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
652652
let val = val as u8;
653653

654654
// C requires that this must always be a valid pointer (C18 §7.1.4).
@@ -661,7 +661,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
661661
.position(|&c| c == val)
662662
{
663663
let idx = u64::try_from(idx).unwrap();
664-
#[allow(clippy::arithmetic_side_effects)] // idx < num, so this never wraps
664+
#[expect(clippy::arithmetic_side_effects)] // idx < num, so this never wraps
665665
let new_ptr = ptr.wrapping_offset(Size::from_bytes(num - idx - 1), this);
666666
this.write_pointer(new_ptr, dest)?;
667667
} else {
@@ -675,7 +675,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
675675
let val = this.read_scalar(val)?.to_i32()?;
676676
let num = this.read_target_usize(num)?;
677677
// The docs say val is "interpreted as unsigned char".
678-
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
678+
#[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
679679
let val = val as u8;
680680

681681
// C requires that this must always be a valid pointer (C18 §7.1.4).

src/shims/io_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
188188
}
189189

190190
/// The inverse of `io_error_to_errnum`.
191-
#[allow(clippy::needless_return)]
191+
#[expect(clippy::needless_return)]
192192
fn try_errnum_to_io_error(
193193
&self,
194194
errnum: Scalar,

src/shims/tls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> Default for TlsData<'tcx> {
5353
impl<'tcx> TlsData<'tcx> {
5454
/// Generate a new TLS key with the given destructor.
5555
/// `max_size` determines the integer size the key has to fit in.
56-
#[allow(clippy::arithmetic_side_effects)]
56+
#[expect(clippy::arithmetic_side_effects)]
5757
pub fn create_tls_key(
5858
&mut self,
5959
dtor: Option<ty::Instance<'tcx>>,

src/shims/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ pub struct DirTable {
385385
}
386386

387387
impl DirTable {
388-
#[allow(clippy::arithmetic_side_effects)]
388+
#[expect(clippy::arithmetic_side_effects)]
389389
fn insert_new(&mut self, read_dir: ReadDir) -> u64 {
390390
let id = self.next_id;
391391
self.next_id += 1;

src/shims/unix/linux/mem.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
2222
let flags = this.read_scalar(flags)?.to_i32()?;
2323

2424
// old_address must be a multiple of the page size
25-
#[allow(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero
25+
#[expect(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero
2626
if old_address.addr().bytes() % this.machine.page_size != 0 || new_size == 0 {
2727
this.set_last_error(LibcError("EINVAL"))?;
2828
return interp_ok(this.eval_libc("MAP_FAILED"));

src/shims/unix/linux/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub fn futex<'tcx>(
182182
// before doing the syscall.
183183
this.atomic_fence(AtomicFenceOrd::SeqCst)?;
184184
let mut n = 0;
185-
#[allow(clippy::arithmetic_side_effects)]
185+
#[expect(clippy::arithmetic_side_effects)]
186186
for _ in 0..val {
187187
if this.futex_wake(addr_usize, bitset)? {
188188
n += 1;

src/shims/unix/mem.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
132132

133133
// addr must be a multiple of the page size, but apart from that munmap is just implemented
134134
// as a dealloc.
135-
#[allow(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero
135+
#[expect(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero
136136
if addr.addr().bytes() % this.machine.page_size != 0 {
137137
return this.set_last_error_and_return_i32(LibcError("EINVAL"));
138138
}

src/shims/unix/sync.rs

-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
685685

686686
let id = rwlock_get_data(this, rwlock_op)?.id;
687687

688-
#[allow(clippy::if_same_then_else)]
689688
if this.rwlock_reader_unlock(id)? || this.rwlock_writer_unlock(id)? {
690689
interp_ok(())
691690
} else {

src/shims/windows/foreign_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn win_absolute<'tcx>(path: &Path) -> InterpResult<'tcx, io::Result<PathBuf>> {
2525
}
2626

2727
#[cfg(unix)]
28-
#[allow(clippy::get_first, clippy::arithmetic_side_effects)]
28+
#[expect(clippy::get_first, clippy::arithmetic_side_effects)]
2929
fn win_absolute<'tcx>(path: &Path) -> InterpResult<'tcx, io::Result<PathBuf>> {
3030
// We are on Unix, so we need to implement parts of the logic ourselves.
3131
let bytes = path.as_os_str().as_encoded_bytes();

src/shims/windows/handle.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl Handle {
6363
let floor_log2 = variant_count.ilog2();
6464

6565
// we need to add one for non powers of two to compensate for the difference
66-
#[allow(clippy::arithmetic_side_effects)] // cannot overflow
66+
#[expect(clippy::arithmetic_side_effects)] // cannot overflow
6767
if variant_count.is_power_of_two() { floor_log2 } else { floor_log2 + 1 }
6868
}
6969

@@ -88,8 +88,7 @@ impl Handle {
8888

8989
// packs the data into the lower `data_size` bits
9090
// and packs the discriminant right above the data
91-
#[allow(clippy::arithmetic_side_effects)] // cannot overflow
92-
return discriminant << data_size | data;
91+
discriminant << data_size | data
9392
}
9493

9594
fn new(discriminant: u32, data: u32) -> Option<Self> {
@@ -107,11 +106,10 @@ impl Handle {
107106
let data_size = u32::BITS.strict_sub(disc_size);
108107

109108
// the lower `data_size` bits of this mask are 1
110-
#[allow(clippy::arithmetic_side_effects)] // cannot overflow
109+
#[expect(clippy::arithmetic_side_effects)] // cannot overflow
111110
let data_mask = 2u32.pow(data_size) - 1;
112111

113112
// the discriminant is stored right above the lower `data_size` bits
114-
#[allow(clippy::arithmetic_side_effects)] // cannot overflow
115113
let discriminant = handle >> data_size;
116114

117115
// the data is stored in the lower `data_size` bits
@@ -123,7 +121,7 @@ impl Handle {
123121
pub fn to_scalar(self, cx: &impl HasDataLayout) -> Scalar {
124122
// 64-bit handles are sign extended 32-bit handles
125123
// see https://docs.microsoft.com/en-us/windows/win32/winprog64/interprocess-communication
126-
#[allow(clippy::cast_possible_wrap)] // we want it to wrap
124+
#[expect(clippy::cast_possible_wrap)] // we want it to wrap
127125
let signed_handle = self.to_packed() as i32;
128126
Scalar::from_target_isize(signed_handle.into(), cx)
129127
}
@@ -134,7 +132,7 @@ impl Handle {
134132
) -> InterpResult<'tcx, Option<Self>> {
135133
let sign_extended_handle = handle.to_target_isize(cx)?;
136134

137-
#[allow(clippy::cast_sign_loss)] // we want to lose the sign
135+
#[expect(clippy::cast_sign_loss)] // we want to lose the sign
138136
let handle = if let Ok(signed_handle) = i32::try_from(sign_extended_handle) {
139137
signed_handle as u32
140138
} else {

src/shims/x86/gfni.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn affine_transform<'tcx>(
136136
// This is a evaluated at compile time. Trait based conversion is not available.
137137
/// See <https://www.corsix.org/content/galois-field-instructions-2021-cpus> for the
138138
/// definition of `gf_inv` which was used for the creation of this table.
139-
#[allow(clippy::cast_possible_truncation)]
139+
#[expect(clippy::cast_possible_truncation)]
140140
static TABLE: [u8; 256] = {
141141
let mut array = [0; 256];
142142

@@ -163,7 +163,7 @@ static TABLE: [u8; 256] = {
163163
/// polynomial representation with the reduction polynomial x^8 + x^4 + x^3 + x + 1.
164164
/// See <https://www.corsix.org/content/galois-field-instructions-2021-cpus> for details.
165165
// This is a const function. Trait based conversion is not available.
166-
#[allow(clippy::cast_possible_truncation)]
166+
#[expect(clippy::cast_possible_truncation)]
167167
const fn gf2p8_mul(left: u8, right: u8) -> u8 {
168168
// This implementation is based on the `gf2p8mul_byte` definition found inside the Intel intrinsics guide.
169169
// See https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=gf2p8mul

src/shims/x86/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ enum FloatUnaryOp {
397397
}
398398

399399
/// Performs `which` scalar operation on `op` and returns the result.
400-
#[allow(clippy::arithmetic_side_effects)] // floating point operations without side effects
401400
fn unary_op_f32<'tcx>(
402401
this: &mut crate::MiriInterpCx<'tcx>,
403402
which: FloatUnaryOp,
@@ -426,7 +425,7 @@ fn unary_op_f32<'tcx>(
426425
}
427426

428427
/// Disturbes a floating-point result by a relative error on the order of (-2^scale, 2^scale).
429-
#[allow(clippy::arithmetic_side_effects)] // floating point arithmetic cannot panic
428+
#[expect(clippy::arithmetic_side_effects)] // floating point arithmetic cannot panic
430429
fn apply_random_float_error<F: rustc_apfloat::Float>(
431430
this: &mut crate::MiriInterpCx<'_>,
432431
val: F,
@@ -1000,7 +999,6 @@ fn mask_load<'tcx>(
1000999
let dest = this.project_index(&dest, i)?;
10011000

10021001
if this.read_scalar(&mask)?.to_uint(mask_item_size)? >> high_bit_offset != 0 {
1003-
#[allow(clippy::arithmetic_side_effects)] // `Size` arithmetic is checked
10041002
let ptr = ptr.wrapping_offset(dest.layout.size * i, &this.tcx);
10051003
// Unaligned copy, which is what we want.
10061004
this.mem_copy(ptr, dest.ptr(), dest.layout.size, /*nonoverlapping*/ true)?;
@@ -1036,7 +1034,6 @@ fn mask_store<'tcx>(
10361034
if this.read_scalar(&mask)?.to_uint(mask_item_size)? >> high_bit_offset != 0 {
10371035
// *Non-inbounds* pointer arithmetic to compute the destination.
10381036
// (That's why we can't use a place projection.)
1039-
#[allow(clippy::arithmetic_side_effects)] // `Size` arithmetic is checked
10401037
let ptr = ptr.wrapping_offset(value.layout.size * i, &this.tcx);
10411038
// Deref the pointer *unaligned*, and do the copy.
10421039
let dest = this.ptr_to_mplace_unaligned(ptr, value.layout);
@@ -1135,7 +1132,7 @@ fn pmulhrsw<'tcx>(
11351132

11361133
// The result of this operation can overflow a signed 16-bit integer.
11371134
// When `left` and `right` are -0x8000, the result is 0x8000.
1138-
#[allow(clippy::cast_possible_truncation)]
1135+
#[expect(clippy::cast_possible_truncation)]
11391136
let res = res as i16;
11401137

11411138
this.write_scalar(Scalar::from_i16(res), &dest)?;

src/shims/x86/sse42.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const USE_SIGNED: u8 = 2;
6868
/// The mask may be negated if negation flags inside the immediate byte are set.
6969
///
7070
/// For more information, see the Intel Software Developer's Manual, Vol. 2b, Chapter 4.1.
71-
#[allow(clippy::arithmetic_side_effects)]
71+
#[expect(clippy::arithmetic_side_effects)]
7272
fn compare_strings<'tcx>(
7373
this: &mut MiriInterpCx<'tcx>,
7474
str1: &OpTy<'tcx>,
@@ -444,7 +444,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
444444
let crc = if bit_size == 64 {
445445
// The 64-bit version will only consider the lower 32 bits,
446446
// while the upper 32 bits get discarded.
447-
#[allow(clippy::cast_possible_truncation)]
447+
#[expect(clippy::cast_possible_truncation)]
448448
u128::from((left.to_u64()? as u32).reverse_bits())
449449
} else {
450450
u128::from(left.to_u32()?.reverse_bits())

tests/pass/shims/x86/intrinsics-sha.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ unsafe fn schedule(v0: __m128i, v1: __m128i, v2: __m128i, v3: __m128i) -> __m128
181181
}
182182

183183
// we use unaligned loads with `__m128i` pointers
184-
#[allow(clippy::cast_ptr_alignment)]
184+
#[expect(clippy::cast_ptr_alignment)]
185185
#[target_feature(enable = "sha,sse2,ssse3,sse4.1")]
186186
unsafe fn digest_blocks(state: &mut [u32; 8], blocks: &[[u8; 64]]) {
187187
#[allow(non_snake_case)]

0 commit comments

Comments
 (0)