Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: kunit: fix warning when !CONFIG_PRINTK

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 adding a no-op assignment using `args` when `CONFIG_PRINTK`
is not set.

Fixes: a66d733da801 ("rust: support running Rust documentation tests as KUnit ones")
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: David Gow <david@davidgow.net>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Alexandre Courbot and committed by
Shuah Khan
7dd34dfc 03464a48

+8
+8
rust/kernel/kunit.rs
··· 14 14 /// Public but hidden since it should only be used from KUnit generated code. 15 15 #[doc(hidden)] 16 16 pub fn err(args: fmt::Arguments<'_>) { 17 + // `args` is unused if `CONFIG_PRINTK` is not set - this avoids a build-time warning. 18 + #[cfg(not(CONFIG_PRINTK))] 19 + let _ = args; 20 + 17 21 // SAFETY: The format string is null-terminated and the `%pA` specifier matches the argument we 18 22 // are passing. 19 23 #[cfg(CONFIG_PRINTK)] ··· 34 30 /// Public but hidden since it should only be used from KUnit generated code. 35 31 #[doc(hidden)] 36 32 pub fn info(args: fmt::Arguments<'_>) { 33 + // `args` is unused if `CONFIG_PRINTK` is not set - this avoids a build-time warning. 34 + #[cfg(not(CONFIG_PRINTK))] 35 + let _ = args; 36 + 37 37 // SAFETY: The format string is null-terminated and the `%pA` specifier matches the argument we 38 38 // are passing. 39 39 #[cfg(CONFIG_PRINTK)]