Re: [PATCH v1] rust: bug: prevent dead_code warning from warn_on!'s flags constant

"Gary Guo" <[email protected]>
Newsgroups org.kernel.vger.rust-for-linux
Message-ID <[email protected]>
On Fri Jul 24, 2026 at 5:08 AM BST, FUJITA Tomonori wrote:
> On Fri, 24 Jul 2026 00:40:04 +0100
> "Gary Guo" <[email protected]> wrote:
>
>>> diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
>>> index ed943960f851..2fd7ee25abcb 100644
>>> --- a/rust/kernel/bug.rs
>>> +++ b/rust/kernel/bug.rs
>>> @@ -123,9 +123,9 @@ macro_rules! warn_on {
>>>          const _COND_STR: &str = file!();
>>>  
>>>          if cond {
>>> -            const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
>>> +            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, _WARN_ON_FLAGS);
>> 
>> Hmm, why bother adding a const for this rather than just invoke
>> 
>>     $crate::warn_flags!(
>>         _COND_STR,
>>         const { ... }
>>     )
>> 
>> ?
>
> Ah, `(const { ... })` works.
>
>
>> Also, the proper fix would be to mark it as used in the `warn_flags` macro
>> that discard the expression.
>> 
>>     if false {
>>         _ = $flags;
>>     }
>
>
> Yeah, having the callee that discards the argument consume it is more
> logical than working around it at the caller. I'll send v2 shortly.
>
> The same reasoning applies to `$file`. Since there is no warning right
> now, I'll rename `_COND_STR` to `COND_STR` and consume `$file` in a
> separate patch for consistency.

Given that this is closely related to $flags I'd do it in a single patch.

Best,
Gary
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.