Skip to contentSkip to conversation

rust: allow `unknown_lints` in the generated bindings

PATCH In review John Hubbard 2 participants 2 messages Sep 11 – Sep 12

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).
Assisted-by LLM
---
 rust/bindings/lib.rs | 2 ++
 rust/uapi/lib.rs     | 2 ++
 2 files changed, 4 insertions(+)
rust/bindings/lib.rs +2 -0
index 812f8e5a08d5..a3af57d7d137 100644
@@ -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
index 797ead5b5626..361b490acc25 100644
@@ -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
reviewer
#1 lore raw
Quoted 9 lines · John Hubbard

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.

Quoted 6 lines

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.

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 LLM
---
 rust/bindings/lib.rs | 2 ++
 rust/uapi/lib.rs     | 2 ++
 2 files changed, 4 insertions(+)
rust/bindings/lib.rs +2 -0
index 812f8e5a08d5..a3af57d7d137 100644
@@ -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
index 797ead5b5626..361b490acc25 100644
@@ -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