Skip to content

Commit 918ca38

Browse files
committed
Resolve unnecessary_transmutes lints
These appeared in a later nightly. In compiler-builtins we can apply the suggestion, but in `libm` we need to ignore them since `fx::from_bits` is not `const` at the MSRV. `clippy::uninlined_format_args` also seems to have gotten stricter, so fix those here.
1 parent fdbefb3 commit 918ca38

File tree

5 files changed

+20
-30
lines changed

5 files changed

+20
-30
lines changed

builtins-test/tests/mul.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ mod int_mul {
1818
let mul1: $i = $fn(x, y);
1919
if mul0 != mul1 {
2020
panic!(
21-
"{}({}, {}): std: {}, builtins: {}",
22-
stringify!($fn), x, y, mul0, mul1
21+
"{func}({x}, {y}): std: {mul0}, builtins: {mul1}",
22+
func = stringify!($fn),
2323
);
2424
}
2525
});
@@ -52,8 +52,8 @@ mod int_overflowing_mul {
5252
let o1 = o1 != 0;
5353
if mul0 != mul1 || o0 != o1 {
5454
panic!(
55-
"{}({}, {}): std: ({}, {}), builtins: ({}, {})",
56-
stringify!($fn), x, y, mul0, o0, mul1, o1
55+
"{func}({x}, {y}): std: ({mul0}, {o0}), builtins: ({mul1}, {o1})",
56+
func = stringify!($fn),
5757
);
5858
}
5959
});
@@ -77,20 +77,14 @@ mod int_overflowing_mul {
7777
let (mul0, o0) = x.overflowing_mul(y);
7878
let mul1 = __rust_u128_mulo(x, y, &mut o1);
7979
if mul0 != mul1 || i32::from(o0) != o1 {
80-
panic!(
81-
"__rust_u128_mulo({}, {}): std: ({}, {}), builtins: ({}, {})",
82-
x, y, mul0, o0, mul1, o1
83-
);
80+
panic!("__rust_u128_mulo({x}, {y}): std: ({mul0}, {o0}), builtins: ({mul1}, {o1})",);
8481
}
8582
let x = x as i128;
8683
let y = y as i128;
8784
let (mul0, o0) = x.overflowing_mul(y);
8885
let mul1 = __rust_i128_mulo(x, y, &mut o1);
8986
if mul0 != mul1 || i32::from(o0) != o1 {
90-
panic!(
91-
"__rust_i128_mulo({}, {}): std: ({}, {}), builtins: ({}, {})",
92-
x, y, mul0, o0, mul1, o1
93-
);
87+
panic!("__rust_i128_mulo({x}, {y}): std: ({mul0}, {o0}), builtins: ({mul1}, {o1})",);
9488
}
9589
});
9690
}
@@ -109,8 +103,8 @@ macro_rules! float_mul {
109103
let mul1: $f = $fn(x, y);
110104
if !Float::eq_repr(mul0, mul1) {
111105
panic!(
112-
"{}({:?}, {:?}): std: {:?}, builtins: {:?}",
113-
stringify!($fn), x, y, mul0, mul1
106+
"{func}({x:?}, {y:?}): std: {mul0:?}, builtins: {mul1:?}",
107+
func = stringify!($fn),
114108
);
115109
}
116110
});

compiler-builtins/build.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn aarch64_symbol(ordering: Ordering) -> &'static str {
137137
Ordering::Acquire => "acq",
138138
Ordering::Release => "rel",
139139
Ordering::AcqRel => "acq_rel",
140-
_ => panic!("unknown symbol for {:?}", ordering),
140+
_ => panic!("unknown symbol for {ordering:?}"),
141141
}
142142
}
143143

@@ -229,7 +229,7 @@ fn configure_check_cfg() {
229229

230230
for op_size in op_sizes {
231231
for ordering in ["relax", "acq", "rel", "acq_rel"] {
232-
aarch_atomic.push(format!("__aarch64_{}{}_{}", aarch_op, op_size, ordering));
232+
aarch_atomic.push(format!("__aarch64_{aarch_op}{op_size}_{ordering}"));
233233
}
234234
}
235235
}
@@ -239,10 +239,7 @@ fn configure_check_cfg() {
239239
.copied()
240240
.chain(aarch_atomic.iter().map(|s| s.as_str()))
241241
{
242-
println!(
243-
"cargo::rustc-check-cfg=cfg({}, values(\"optimized-c\"))",
244-
fn_name
245-
);
242+
println!("cargo::rustc-check-cfg=cfg({fn_name}, values(\"optimized-c\"))",);
246243
}
247244

248245
// Rustc is unaware of sparc target features, but this does show up from

compiler-builtins/src/mem/impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ unsafe fn read_usize_unaligned(x: *const usize) -> usize {
3838
// Do not use `core::ptr::read_unaligned` here, since it calls `copy_nonoverlapping` which
3939
// is translated to memcpy in LLVM.
4040
let x_read = (x as *const [u8; core::mem::size_of::<usize>()]).read();
41-
core::mem::transmute(x_read)
41+
usize::from_ne_bytes(x_read)
4242
}
4343

4444
/// Loads a `T`-sized chunk from `src` into `dst` at offset `offset`, if that does not exceed

libm/src/math/pow.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,7 @@ mod tests {
452452
} else {
453453
pow(base, exponent) == expected
454454
},
455-
"{} ** {} was {} instead of {}",
456-
base,
457-
exponent,
458-
res,
459-
expected
455+
"{base} ** {exp} was {res} instead of {expected}",
460456
);
461457
}
462458

@@ -486,10 +482,7 @@ mod tests {
486482
} else {
487483
exp == res
488484
},
489-
"test for {} was {} instead of {}",
490-
val,
491-
res,
492-
exp
485+
"test for {val} was {res} instead of {exp}",
493486
);
494487
})
495488
});

libm/src/math/support/float_traits.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unknown_lints)] // FIXME(msrv) we shouldn't need this
2+
13
use core::{fmt, mem, ops};
24

35
use super::int_traits::{CastFrom, Int, MinInt};
@@ -344,24 +346,28 @@ float_impl!(
344346
/* FIXME(msrv): vendor some things that are not const stable at our MSRV */
345347

346348
/// `f32::from_bits`
349+
#[allow(unnecessary_transmutes)] // lint appears in newer versions of Rust
347350
pub const fn f32_from_bits(bits: u32) -> f32 {
348351
// SAFETY: POD cast with no preconditions
349352
unsafe { mem::transmute::<u32, f32>(bits) }
350353
}
351354

352355
/// `f32::to_bits`
356+
#[allow(unnecessary_transmutes)] // lint appears in newer versions of Rust
353357
pub const fn f32_to_bits(x: f32) -> u32 {
354358
// SAFETY: POD cast with no preconditions
355359
unsafe { mem::transmute::<f32, u32>(x) }
356360
}
357361

358362
/// `f64::from_bits`
363+
#[allow(unnecessary_transmutes)] // lint appears in newer versions of Rust
359364
pub const fn f64_from_bits(bits: u64) -> f64 {
360365
// SAFETY: POD cast with no preconditions
361366
unsafe { mem::transmute::<u64, f64>(bits) }
362367
}
363368

364369
/// `f64::to_bits`
370+
#[allow(unnecessary_transmutes)] // lint appears in newer versions of Rust
365371
pub const fn f64_to_bits(x: f64) -> u64 {
366372
// SAFETY: POD cast with no preconditions
367373
unsafe { mem::transmute::<f64, u64>(x) }

0 commit comments

Comments
 (0)