Skip to content

Commit 7dd34df

Browse files
Gnuroushuahkh
authored andcommitted
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: a66d733 ("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>
1 parent 03464a4 commit 7dd34df

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

rust/kernel/kunit.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ use crate::prelude::*;
1414
/// Public but hidden since it should only be used from KUnit generated code.
1515
#[doc(hidden)]
1616
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+
1721
// SAFETY: The format string is null-terminated and the `%pA` specifier matches the argument we
1822
// are passing.
1923
#[cfg(CONFIG_PRINTK)]
@@ -30,6 +34,10 @@ pub fn err(args: fmt::Arguments<'_>) {
3034
/// Public but hidden since it should only be used from KUnit generated code.
3135
#[doc(hidden)]
3236
pub fn info(args: fmt::Arguments<'_>) {
37+
// `args` is unused if `CONFIG_PRINTK` is not set - this avoids a build-time warning.
38+
#[cfg(not(CONFIG_PRINTK))]
39+
let _ = args;
40+
3341
// SAFETY: The format string is null-terminated and the `%pA` specifier matches the argument we
3442
// are passing.
3543
#[cfg(CONFIG_PRINTK)]

0 commit comments

Comments
 (0)