]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: enable `clippy::ignored_unit_patterns` lint
authorMiguel Ojeda <ojeda@kernel.org>
Wed, 4 Sep 2024 20:43:35 +0000 (22:43 +0200)
committerMiguel Ojeda <ojeda@kernel.org>
Mon, 7 Oct 2024 19:39:05 +0000 (21:39 +0200)
In Rust 1.73.0, Clippy introduced the `ignored_unit_patterns` lint [1]:

> Matching with `()` explicitly instead of `_` outlines the fact that
> the pattern contains no data. Also it would detect a type change
> that `_` would ignore.

There is only a single case that requires a change:

    error: matching over `()` is more explicit
       --> rust/kernel/types.rs:176:45
        |
    176 |         ScopeGuard::new_with_data((), move |_| cleanup())
        |                                             ^ help: use `()` instead of `_`: `()`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns
        = note: requested on the command line with `-D clippy::ignored-unit-patterns`

Thus clean it up and enable the lint -- no functional change intended.

Link: https://rust-lang.github.io/rust-clippy/master/index.html#/ignored_unit_patterns
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Tested-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/20240904204347.168520-8-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Makefile
rust/kernel/types.rs

index 3476afc707886420e3e9039cf48523189bd6b30c..b0696cd0599c7ab98167a69f38292d56d8a07f7a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -453,6 +453,7 @@ export rust_common_flags := --edition=2021 \
                            -Wunreachable_pub \
                            -Wclippy::all \
                            -Wclippy::dbg_macro \
+                           -Wclippy::ignored_unit_patterns \
                            -Wclippy::mut_mut \
                            -Wclippy::needless_bitwise_bool \
                            -Wclippy::needless_continue \
index fd8e2b6039e04e0157b13587ae7fcd7c954e253e..28d9e5ea3df451556ac1b1c62e15f72c1aca68ec 100644 (file)
@@ -225,7 +225,7 @@ impl<T, F: FnOnce(T)> ScopeGuard<T, F> {
 impl ScopeGuard<(), fn(())> {
     /// Creates a new guarded object with the given cleanup function.
     pub fn new(cleanup: impl FnOnce()) -> ScopeGuard<(), impl FnOnce(())> {
-        ScopeGuard::new_with_data((), move |_| cleanup())
+        ScopeGuard::new_with_data((), move |()| cleanup())
     }
 }