Rust for Linux List
 help / color / mirror / Atom feed
From: FUJITA Tomonori <tomo@flapping.org>
To: ojeda@kernel.org
Cc: arnd@arndb.de, krzk@kernel.org, alexandre.belloni@bootlin.com,
	linusw@kernel.org, chenhuacai@kernel.org, boqun@kernel.org,
	gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
	a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
	dakr@kernel.org, daniel.almeida@collabora.com, tamird@kernel.org,
	acourbot@nvidia.com, work@onurozkan.dev,
	rust-for-linux@vger.kernel.org, fustini@kernel.org,
	linux-arm-kernel@lists.infradead.org, soc@lists.linux.dev,
	kernel@xen0n.name, loongarch@lists.linux.dev,
	stable@vger.kernel.org
Subject: Re: [PATCH] rust: bug: fix `dead_code` warning in `warn_on!`
Date: Sat, 08 Aug 2026 07:43:41 +0900 (JST)	[thread overview]
Message-ID: <20260808.074341.1056015191905819805.tomo@flapping.org> (raw)
In-Reply-To: <20260807221429.155946-1-ojeda@kernel.org>

On Sat,  8 Aug 2026 00:14:29 +0200
Miguel Ojeda <ojeda@kernel.org> 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: stable@vger.kernel.org
> Fixes: dff64b072708 ("rust: Add warn_on macro")
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> Either this or adding an underscore.
> 
>  rust/kernel/bug.rs | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
> index ed943960f851..874adb93cdfe 100644
> --- a/rust/kernel/bug.rs
> +++ b/rust/kernel/bug.rs
> @@ -123,9 +123,10 @@ macro_rules! warn_on {
>          const _COND_STR: &str = file!();
> 
>          if cond {
> -            const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
> -
> -            $crate::warn_flags!(_COND_STR, WARN_ON_FLAGS);
> +            $crate::warn_flags!(
> +                _COND_STR,
> +                $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN)
> +            );
>          }
>          cond
>      }};
> 
> base-commit: dc01dfb37b34beeefcfe1c3055364d41a4070c7e
> --
> 2.55.0

I sent a fix for this bug a few days ago:

https://lore.kernel.org/all/20260801024841.786664-1-tomo@flapping.org/


If you prefer the simpler version, v1 might work.

https://lore.kernel.org/all/20260720035510.4048145-1-tomo@flapping.org/

  parent reply	other threads:[~2026-08-07 22:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 22:14 [PATCH] rust: bug: fix `dead_code` warning in `warn_on!` Miguel Ojeda
2026-08-07 22:19 ` Miguel Ojeda
2026-08-07 22:43 ` FUJITA Tomonori [this message]
2026-08-07 23:21   ` Miguel Ojeda
2026-08-08  5:30     ` FUJITA Tomonori
2026-08-08 19:40       ` Miguel Ojeda
2026-08-09  0:50         ` FUJITA Tomonori
2026-08-09  3:01           ` Miguel Ojeda
2026-08-09 14:41     ` Gary Guo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260808.074341.1056015191905819805.tomo@flapping.org \
    --to=tomo@flapping.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=aliceryhl@google.com \
    --cc=arnd@arndb.de \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=fustini@kernel.org \
    --cc=gary@garyguo.net \
    --cc=kernel@xen0n.name \
    --cc=krzk@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=loongarch@lists.linux.dev \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=soc@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox