Skip to content

Commit 3d02832

Browse files
committed
rust: clean Rust 1.88.0's unnecessary_transmutes lint
Starting with Rust 1.88.0 [1], `rustc` has a new lint that catches unnecessary transmutes, e.g. error: unnecessary transmute --> rust/uapi/uapi_generated.rs:23242:18 | 23242 | unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this with: `(self._bitfield_1.get(0usize, 1u8) as u8 == 1)` | = note: `-D unnecessary-transmutes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unnecessary_transmutes)]` There are a lot of them (at least 300), but luckily they are all in `bindgen`-generated code. Thus clean all up by allowing it there. Since unknown lints trigger a lint itself in older compilers, do it conditionally so that we can keep the `unknown_lints` lint enabled. Cc: [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs). Link: rust-lang/rust#136083 [1] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent b443265 commit 3d02832

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

init/Kconfig

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ config LD_CAN_USE_KEEP_IN_OVERLAY
140140
config RUSTC_HAS_COERCE_POINTEE
141141
def_bool RUSTC_VERSION >= 108400
142142

143+
config RUSTC_HAS_UNNECESSARY_TRANSMUTES
144+
def_bool RUSTC_VERSION >= 108800
145+
143146
config PAHOLE_VERSION
144147
int
145148
default $(shell,$(srctree)/scripts/pahole-version.sh $(PAHOLE))

rust/bindings/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#[allow(dead_code)]
2828
#[allow(clippy::undocumented_unsafe_blocks)]
29+
#[cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_transmutes))]
2930
mod bindings_raw {
3031
// Manual definition for blocklisted types.
3132
type __kernel_size_t = usize;

rust/uapi/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
unreachable_pub,
2525
unsafe_op_in_unsafe_fn
2626
)]
27+
#![cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_transmutes))]
2728

2829
// Manual definition of blocklisted types.
2930
type __kernel_size_t = usize;

0 commit comments

Comments
 (0)