rust: init: allow `dead_code` warnings for Rust >= 1.89.0
Subsystems (2)
Miguel Ojeda
maintainerPATCH 1/1 rust: init: allow `dead_code` warnings for Rust >= 1.89.0
Starting with Rust 1.89.0 (expected 2025-08-07), the Rust compiler may warn:
error: trait `MustNotImplDrop` is never used
--> rust/kernel/init/macros.rs:927:15
|
927 | trait MustNotImplDrop {}
| ^^^^^^^^^^^^^^^
|
::: rust/kernel/sync/arc.rs:133:1
|
133 | #[pin_data]
| ----------- in this procedural macro expansion
|
= note: `-D dead-code` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(dead_code)]`
= note: this error originates in the macro `$crate::__pin_data`
which comes from the expansion of the attribute macro
`pin_data` (in Nightly builds, run with
-Z macro-backtrace for more info)Thus allow it to clean it up.
This does not happen in mainline nor 6.15.y, because there the macro was moved out of the kernel crate, and dead_code warnings are not emitted if the macro is foreign to the crate. Thus this patch is directly sent to stable and intended for 6.12.y only.
Similarly, it is not needed in previous LTSs, because there the Rust version is pinned.
---
Greg, Sasha: please note that an equivalent patch is _not_ in mainline.
We could put these allows in mainline (they wouldn't hurt), but it isn't a good idea to add things in mainline for the only reason of backporting them, thus I am sending this directly to stable.
The patch is pretty safe -- there is no actual code change.
rust/kernel/init/macros.rs | 2 ++ 1 file changed, 2 insertions(+)
rust/kernel/init/macros.rs +2 -0
@@ -924,6 +924,7 @@ impl<'__pin, $($impl_generics)*> ::core::marker::Unpin for $name<$($ty_generics)// We prevent this by creating a trait that will be implemented for all types implementing // `Drop`. Additionally we will implement this trait for the struct leading to a conflict, // if it also implements `Drop` +#[allow(dead_code)] trait MustNotImplDrop {}#[expect(drop_bounds)] impl <T : ::core::ops::Drop >MustNotImplDrop for T {}
@@ -932,6 +933,7 @@ impl<$($impl_generics)*> MustNotImplDrop for $name<$($ty_generics)*>// We also take care to prevent users from writing a useless `PinnedDrop` implementation. // They might implement `PinnedDrop` correctly for the struct, but forget to give // `PinnedDrop` as the parameter to `#[pin_data]`. +#[allow(dead_code)] #[expect(non_camel_case_types)] trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {} impl<T: $crate::init::PinnedDrop>
base-commit: fbad404f04d758c52bae79ca20d0e7fe5fef91d3 --
2.50.1
Quoted 21 lines · Miguel Ojeda
Starting with Rust 1.89.0 (expected 2025-08-07), the Rust compiler may warn:
error: trait `MustNotImplDrop` is never used --> rust/kernel/init/macros.rs:927:15 | 927 | trait MustNotImplDrop {} | ^^^^^^^^^^^^^^^ | ::: rust/kernel/sync/arc.rs:133:1 | 133 | #[pin_data] | ----------- in this procedural macro expansion | = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]` = note: this error originates in the macro `$crate::__pin_data` which comes from the expansion of the attribute macro `pin_data` (in Nightly builds, run with -Z macro-backtrace for more info)
Quoted 1 line
Thus
allowit to clean it up.
This is a bit strange, I can't directly reproduce the issue... I already get this warning in 1.88:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=465f71a848e77ac3f7a96a0af6bc9e2a
Quoted 10 lines
This does not happen in mainline nor 6.15.y, because there the macro was moved out of the
kernelcrate, anddead_codewarnings are not emitted if the macro is foreign to the crate. Thus this patch is directly sent to stable and intended for 6.12.y only.Similarly, it is not needed in previous LTSs, because there the Rust version is pinned.
Cc Benno Lossin <[email protected]>Signed-off-by Miguel Ojeda <[email protected]>
Anyways the patch itself looks fine, nobody should care about the dead-code warning (since it is in fact used to prevent Drop being implemented).
---
Cheers,
Benno
Quoted 36 lines
---
Greg, Sasha: please note that an equivalent patch is _not_ in mainline.We could put these
allows in mainline (they wouldn't hurt), but it isn't a good idea to add things in mainline for the only reason of backporting them, thus I am sending this directly to stable.The patch is pretty safe -- there is no actual code change.
rust/kernel/init/macros.rs | 2 ++ 1 file changed, 2 insertions(+)rust/kernel/init/macros.rs +2
-0@@ -924,6 +924,7 @@ impl<'__pin, $($impl_generics)*> ::core::marker::Unpin for $name<$($ty_generics)// We prevent this by creating a trait that will be implemented for all types implementing // `Drop`. Additionally we will implement this trait for the struct leading to a conflict, // if it also implements `Drop` +#[allow(dead_code)] trait MustNotImplDrop {}#[expect(drop_bounds)] impl <T : ::core::ops::Drop >MustNotImplDrop for T {}@@ -932,6 +933,7 @@ impl<$($impl_generics)*> MustNotImplDrop for $name<$($ty_generics)*>// We also take care to prevent users from writing a useless `PinnedDrop` implementation. // They might implement `PinnedDrop` correctly for the struct, but forget to give // `PinnedDrop` as the parameter to `#[pin_data]`. +#[allow(dead_code)] #[expect(non_camel_case_types)] trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {} impl<T: $crate::init::PinnedDrop>base-commit:
fbad404f04d758c52bae79ca20d0e7fe5fef91d3--
2.50.1
Greg Kroah-Hartman
maintainerQuoted 37 lines · Benno Lossin
Quoted 21 lines · Miguel Ojeda
Starting with Rust 1.89.0 (expected 2025-08-07), the Rust compiler may warn:
error: trait `MustNotImplDrop` is never used --> rust/kernel/init/macros.rs:927:15 | 927 | trait MustNotImplDrop {} | ^^^^^^^^^^^^^^^ | ::: rust/kernel/sync/arc.rs:133:1 | 133 | #[pin_data] | ----------- in this procedural macro expansion | = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]` = note: this error originates in the macro `$crate::__pin_data` which comes from the expansion of the attribute macro `pin_data` (in Nightly builds, run with -Z macro-backtrace for more info)Quoted 1 line
Thus
allowit to clean it up.This is a bit strange, I can't directly reproduce the issue... I already get this warning in 1.88:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=465f71a848e77ac3f7a96a0af6bc9e2aQuoted 8 lines
This does not happen in mainline nor 6.15.y, because there the macro was moved out of the
kernelcrate, anddead_codewarnings are not emitted if the macro is foreign to the crate. Thus this patch is directly sent to stable and intended for 6.12.y only.Similarly, it is not needed in previous LTSs, because there the Rust version is pinned.
Quoted 8 lines
Quoted 2 lines
Cc Benno Lossin <[email protected]>Signed-off-by Miguel Ojeda <[email protected]>Anyways the patch itself looks fine, nobody should care about the dead-code warning (since it is in fact used to prevent
Dropbeing implemented).Acked-by Benno Lossin <[email protected]>
Thanks, now queued up.
greg k-h
Patch "rust: init: allow `dead_code` warnings for Rust >= 1.89.0" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: init: allow dead_code warnings for Rust >= 1.89.0
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-init-allow-dead_code-warnings-for-rust-1.89.0.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Sun Jul 13 16:40:56 2025
From: Miguel Ojeda <[email protected]>
Date: Sat, 12 Jul 2025 19:10:38 +0200
Subject: rust: init: allow dead_code warnings for Rust >= 1.89.0
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, Miguel Ojeda <[email protected]>, Alex Gaynor <[email protected]>
Cc: [email protected], "Boqun Feng" <[email protected]>, "Gary Guo" <[email protected]>, "Björn Roy Baron" <[email protected]>, "Benno Lossin" <[email protected]>, "Andreas Hindborg" <[email protected]>, "Alice Ryhl" <[email protected]>, "Trevor Gross" <[email protected]>, [email protected], [email protected], [email protected], "Benno Lossin" <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
Starting with Rust 1.89.0 (expected 2025-08-07), the Rust compiler may warn:
error: trait `MustNotImplDrop` is never used
--> rust/kernel/init/macros.rs:927:15
|
927 | trait MustNotImplDrop {}
| ^^^^^^^^^^^^^^^
|
::: rust/kernel/sync/arc.rs:133:1
|
133 | #[pin_data]
| ----------- in this procedural macro expansion
|
= note: `-D dead-code` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(dead_code)]`
= note: this error originates in the macro `$crate::__pin_data`
which comes from the expansion of the attribute macro
`pin_data` (in Nightly builds, run with
-Z macro-backtrace for more info)Thus allow it to clean it up.
This does not happen in mainline nor 6.15.y, because there the macro was moved out of the kernel crate, and dead_code warnings are not emitted if the macro is foreign to the crate. Thus this patch is directly sent to stable and intended for 6.12.y only.
Similarly, it is not needed in previous LTSs, because there the Rust version is pinned.
--- rust/kernel/init/macros.rs | 2 ++ 1 file changed, 2 insertions(+)
rust/kernel/init/macros.rs +2 -0
@@ -924,6 +924,7 @@ macro_rules! __pin_data {// We prevent this by creating a trait that will be implemented for all types implementing // `Drop`. Additionally we will implement this trait for the struct leading to a conflict, // if it also implements `Drop` +#[allow(dead_code)] trait MustNotImplDrop {}#[expect(drop_bounds)] impl <T : ::core::ops::Drop >MustNotImplDrop for T {}
@@ -932,6 +933,7 @@ macro_rules! __pin_data {// We also take care to prevent users from writing a useless `PinnedDrop` implementation. // They might implement `PinnedDrop` correctly for the struct, but forget to give // `PinnedDrop` as the parameter to `#[pin_data]`. +#[allow(dead_code)] #[expect(non_camel_case_types)] trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {} impl<T: $crate::init::PinnedDrop>
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/rust-init-allow-dead_code-warnings-for-rust-1.89.0.patch