Skip to content

Commit 2a87f8b

Browse files
committed
rust: kbuild: run Clippy for rusttest code
Running Clippy for `rusttest` code is useful to catch issues there too, even if the code is not as critical. In the future, this code may also run in kernelspace and could be copy-pasted. Thus it is useful to keep it under the same standards. For instance, it will now make us add `// SAFETY` comments. It also makes everything more consistent. Thus clean the few issues spotted by Clippy and start running it. Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20241123180639.260191-1-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent f0915ac commit 2a87f8b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

rust/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-ffi rustdoc-macros \
116116
$(obj)/bindings.o FORCE
117117
+$(call if_changed,rustdoc)
118118

119-
quiet_cmd_rustc_test_library = RUSTC TL $<
119+
quiet_cmd_rustc_test_library = $(RUSTC_OR_CLIPPY_QUIET) TL $<
120120
cmd_rustc_test_library = \
121121
OBJTREE=$(abspath $(objtree)) \
122-
$(RUSTC) $(rust_common_flags) \
122+
$(RUSTC_OR_CLIPPY) $(rust_common_flags) \
123123
@$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \
124124
--crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \
125125
--out-dir $(objtree)/$(obj)/test --cfg testlib \
@@ -187,10 +187,10 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
187187

188188
# We cannot use `-Zpanic-abort-tests` because some tests are dynamic,
189189
# so for the moment we skip `-Cpanic=abort`.
190-
quiet_cmd_rustc_test = RUSTC T $<
190+
quiet_cmd_rustc_test = $(RUSTC_OR_CLIPPY_QUIET) T $<
191191
cmd_rustc_test = \
192192
OBJTREE=$(abspath $(objtree)) \
193-
$(RUSTC) --test $(rust_common_flags) \
193+
$(RUSTC_OR_CLIPPY) --test $(rust_common_flags) \
194194
@$(objtree)/include/generated/rustc_cfg \
195195
$(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \
196196
-L$(objtree)/$(obj)/test \

rust/kernel/str.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ macro_rules! c_str {
522522
}
523523

524524
#[cfg(test)]
525+
#[expect(clippy::items_after_test_module)]
525526
mod tests {
526527
use super::*;
527528

@@ -547,7 +548,7 @@ mod tests {
547548
})
548549
}
549550

550-
const ALL_ASCII_CHARS: &'static str =
551+
const ALL_ASCII_CHARS: &str =
551552
"\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\x0f\
552553
\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f \
553554
!\"#$%&'()*+,-./0123456789:;<=>?@\
@@ -581,6 +582,7 @@ mod tests {
581582
fn test_cstr_as_str_unchecked() {
582583
let good_bytes = b"\xf0\x9f\x90\xA7\0";
583584
let checked_cstr = CStr::from_bytes_with_nul(good_bytes).unwrap();
585+
// SAFETY: The contents come from a string literal which contains valid UTF-8.
584586
let unchecked_str = unsafe { checked_cstr.as_str_unchecked() };
585587
assert_eq!(unchecked_str, "🐧");
586588
}

0 commit comments

Comments
 (0)