"Alice Ryhl" <[email protected]> writes:

> On Tue, Feb 24, 2026 at 04:45:30PM +0900, Alexandre Courbot wrote:
>> If `CONFIG_PRINTK` is not set, then the following warnings are issued
>> during build:
>>
>>   warning: unused variable: `args`
>>     --> ../rust/kernel/kunit.rs:16:12
>>     |
>>   16 | pub fn err(args: fmt::Arguments<'_>) {
>>     |            ^^^^ help: if this is intentional, prefix it with an 
>> underscore: `_args`
>>     |
>>     = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by 
>> default
>>
>>   warning: unused variable: `args`
>>     --> ../rust/kernel/kunit.rs:32:13
>>     |
>>   32 | pub fn info(args: fmt::Arguments<'_>) {
>>     |             ^^^^ help: if this is intentional, prefix it with an 
>> underscore: `_args`
>>
>> Fix this by allowing unused variables on these methods for this
>> (arguably rare) case.
>>
>> Fixes: a66d733da801 ("rust: support running Rust documentation tests as 
>> KUnit ones")
>> Signed-off-by: Alexandre Courbot <[email protected]>
>
> I think this would be a better fix:
>
> diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs
> index f93f24a60bdd..dbf3c62ffa09 100644
> --- a/rust/kernel/kunit.rs
> +++ b/rust/kernel/kunit.rs
> @@ -23,6 +23,9 @@ pub fn err(args: fmt::Arguments<'_>) {
>              core::ptr::from_ref(&args).cast::<c_void>(),
>          );
>      }
> +
> +    #[cfg(not(CONFIG_PRINTK))]
> +    let _ = args;
>  }
>
>  /// Prints a KUnit info-level message.
> @@ -39,6 +42,9 @@ pub fn info(args: fmt::Arguments<'_>) {
>              core::ptr::from_ref(&args).cast::<c_void>(),
>          );
>      }
> +
> +    #[cfg(not(CONFIG_PRINTK))]
> +    let _ = args;
>  }
>
>  /// Asserts that a boolean expression is `true` at runtime.

Why not a conditional attribute on the argument?


Best regards,
Andreas Hindborg



Reply via email to