Re: [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
Miguel Ojeda <[email protected]>
| Newsgroups | dev.linux.lists.soc,dev.linux.lists.loongarch,org.infradead.lists.linux-arm-kernel,org.kernel.vger.rust-for-linux,org.kernel.vger.stable |
|---|---|
| Message-ID | <CANiq72kz2Ec119ZW2uiu0-RPHr=Zy5-WRA5tSOYk5it6PqpH2g@mail.gmail.com> |
On Sat, Aug 8, 2026 at 12:14 AM Miguel Ojeda <[email protected]> wrote: > > On arm and loongarch64, or under `CONFIG_BUG=n`, the upcoming SRCU > abstractions from commit > > 59cf3a5bda61 ("rust: sync: add SRCU abstraction") > > use `warn_on!`, which in turn warns: > > error: constant `WARN_ON_FLAGS` is never used > --> rust/kernel/bug.rs:126:19 > | > 126 | const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN); > | ^^^^^^^^^^^^^ > | > ::: rust/kernel/sync/srcu.rs:106:12 > | > 106 | if crate::warn_on!( > | ____________- > 107 | | // SAFETY: By the type invariants, `self` contains a valid and pinned `struct srcu_struct` > 108 | | // and `srcu_readers_active()` only checks the active reader count. > 109 | | unsafe { bindings::srcu_readers_active(ptr) } > 110 | | ) { > | |_________- in this macro invocation > | > = 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::warn_on` (in Nightly builds, run with -Z macro-backtrace for more info) > > The reason is that `warn_flags!` discards both arguments in those cases, > and so the `const` becomes unused. And since it is a macro, it went > unnoticed so far. > > Thus fix it by simplifying by removing the `const`. > > Cc: [email protected] > Fixes: dff64b072708 ("rust: Add warn_on macro") > Signed-off-by: Miguel Ojeda <[email protected]> Sorry, I forgot the Cc to Tomonori: Cc: FUJITA Tomonori <[email protected]> Cheers, Miguel