rust: allow `unknown_lints` in the generated bindings
Subsystems (2)
PATCH 1/1 rust: allow `unknown_lints` in the generated bindings
A build with bindgen 0.73.2 and the minimum supported rustc, 1.85.0, emits about 12000 unknown_lints warnings, all of them in bindgen's generated output. CONFIG_WERROR or W=e turns them into a failed build.
Starting with 0.73.0, bindgen writes #[allow(unnecessary_transmutes)] onto every bitfield accessor and constructor it generates. It does so regardless of --rust-target, which rust/Makefile already sets to 1.85. That lint exists only since rustc 1.88.0.
Commit 7129ea6e242b ("rust: clean Rust 1.88.0's unnecessary_transmutes lint") made the kernel's own attribute conditional, to keep unknown_lints enabled. That condition cannot be put on an attribute that bindgen writes.
Allow unknown_lints in the bindings and uapi crates.
--- rust/bindings/lib.rs | 2 ++ rust/uapi/lib.rs | 2 ++ 2 files changed, 4 insertions(+)
rust/bindings/lib.rs +2 -0
@@ -26,6 +26,8 @@#[allow(clippy::ptr_as_ptr)] #[allow(clippy::ref_as_ptr)] #[allow(clippy::undocumented_unsafe_blocks)] +// `bindgen` emits `#[allow(...)]` for lints newer than the minimum supported `rustc`. +#[allow(unknown_lints)] #[cfg_attr( CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES , allow(unnecessary_transmutes))] #[cfg_attr( CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS,
rust/uapi/lib.rs +2 -0
@@ -23,6 +23,8 @@ unreachable_pub, unsafe_op_in_unsafe_fn )] +// `bindgen` emits `#[allow(...)]` for lints newer than the minimum supported `rustc`. +#![allow(unknown_lints)] #![cfg_attr( CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES , allow(unnecessary_transmutes))] #![cfg_attr( CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS,
base-commit: 3026c6e4f223bdded6448fefe53ff85d9cbe51bd
Signature · 1 line
2.55.0
Gary Guo
reviewerQuoted 9 lines · John Hubbard
A build with bindgen 0.73.2 and the minimum supported rustc, 1.85.0, emits about 12000
unknown_lintswarnings, all of them in bindgen's generated output.CONFIG_WERRORor W=e turns them into a failed build.Starting with 0.73.0, bindgen writes
#[allow(unnecessary_transmutes)]onto every bitfield accessor and constructor it generates. It does so regardless of--rust-target, whichrust/Makefilealready sets to 1.85. That lint exists only since rustc 1.88.0.
Quoted 6 lines
Commit
7129ea6e242b("rust: clean Rust 1.88.0'sunnecessary_transmuteslint") made the kernel's own attribute conditional, to keepunknown_lintsenabled. That condition cannot be put on an attribute that bindgen writes.Allow
unknown_lintsin the bindings and uapi crates.
Already fixed: https://lore.kernel.org/rust-for-linux/CANiq72=fEYa1PygH-XJHONQKqf53dZFuGc-Z7wd4M7yeREq8Vw@mail.gmail.com/
Best,
Gary
Quoted 37 lines
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Assisted-by LLMSigned-off-by John Hubbard <[email protected]>--- rust/bindings/lib.rs | 2 ++ rust/uapi/lib.rs | 2 ++ 2 files changed, 4 insertions(+)rust/bindings/lib.rs +2
-0@@ -26,6 +26,8 @@#[allow(clippy::ptr_as_ptr)] #[allow(clippy::ref_as_ptr)] #[allow(clippy::undocumented_unsafe_blocks)] +// `bindgen` emits `#[allow(...)]` for lints newer than the minimum supported `rustc`. +#[allow(unknown_lints)] #[cfg_attr( CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES , allow(unnecessary_transmutes))] #[cfg_attr( CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS,rust/uapi/lib.rs +2
-0@@ -23,6 +23,8 @@ unreachable_pub, unsafe_op_in_unsafe_fn )] +// `bindgen` emits `#[allow(...)]` for lints newer than the minimum supported `rustc`. +#![allow(unknown_lints)] #![cfg_attr( CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES , allow(unnecessary_transmutes))] #![cfg_attr( CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS,base-commit:
3026c6e4f223bdded6448fefe53ff85d9cbe51bd