]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: kbuild: run Clippy for `rusttest` code
authorMiguel Ojeda <ojeda@kernel.org>
Sat, 23 Nov 2024 18:06:38 +0000 (19:06 +0100)
committerMiguel Ojeda <ojeda@kernel.org>
Thu, 9 Jan 2025 23:17:25 +0000 (00:17 +0100)
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>
rust/Makefile
rust/kernel/str.rs

index a40a3936126d603836e0ec9b42a1285916b60e45..161e7cf67c97c1c11c18eba8994a0203572a2d4a 100644 (file)
@@ -116,10 +116,10 @@ rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-ffi rustdoc-macros \
     $(obj)/bindings.o FORCE
        +$(call if_changed,rustdoc)
 
-quiet_cmd_rustc_test_library = RUSTC TL $<
+quiet_cmd_rustc_test_library = $(RUSTC_OR_CLIPPY_QUIET) TL $<
       cmd_rustc_test_library = \
        OBJTREE=$(abspath $(objtree)) \
-       $(RUSTC) $(rust_common_flags) \
+       $(RUSTC_OR_CLIPPY) $(rust_common_flags) \
                @$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \
                --crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \
                --out-dir $(objtree)/$(obj)/test --cfg testlib \
@@ -187,10 +187,10 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
 
 # We cannot use `-Zpanic-abort-tests` because some tests are dynamic,
 # so for the moment we skip `-Cpanic=abort`.
-quiet_cmd_rustc_test = RUSTC T  $<
+quiet_cmd_rustc_test = $(RUSTC_OR_CLIPPY_QUIET) T  $<
       cmd_rustc_test = \
        OBJTREE=$(abspath $(objtree)) \
-       $(RUSTC) --test $(rust_common_flags) \
+       $(RUSTC_OR_CLIPPY) --test $(rust_common_flags) \
                @$(objtree)/include/generated/rustc_cfg \
                $(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \
                -L$(objtree)/$(obj)/test \
index 0f2765463dc840dec18d8a2ac905358e703260f1..5dfddb0d41d9807acd2cd97832e252ddab4ad066 100644 (file)
@@ -522,6 +522,7 @@ macro_rules! c_str {
 }
 
 #[cfg(test)]
+#[expect(clippy::items_after_test_module)]
 mod tests {
     use super::*;
 
@@ -547,7 +548,7 @@ mod tests {
         })
     }
 
-    const ALL_ASCII_CHARS: &'static str =
+    const ALL_ASCII_CHARS: &str =
         "\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\x0f\
         \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f \
         !\"#$%&'()*+,-./0123456789:;<=>?@\
@@ -581,6 +582,7 @@ mod tests {
     fn test_cstr_as_str_unchecked() {
         let good_bytes = b"\xf0\x9f\x90\xA7\0";
         let checked_cstr = CStr::from_bytes_with_nul(good_bytes).unwrap();
+        // SAFETY: The contents come from a string literal which contains valid UTF-8.
         let unchecked_str = unsafe { checked_cstr.as_str_unchecked() };
         assert_eq!(unchecked_str, "🐧");
     }