]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: allow `clippy::unwrap_or_default` globally
authorAlexandre Courbot <acourbot@nvidia.com>
Wed, 8 Jul 2026 10:49:26 +0000 (19:49 +0900)
committerMiguel Ojeda <ojeda@kernel.org>
Thu, 9 Jul 2026 21:49:49 +0000 (23:49 +0200)
Starting with rustc 1.88, the `clippy::unwrap_or_default` lint triggers
on `rust/kernel/soc.rs` if `CONFIG_CC_OPTIMIZE_FOR_SIZE=y`:

    warning: use of `unwrap_or` to construct default value
      --> ../rust/kernel/soc.rs:66:10
      |
   66 |         .unwrap_or(core::ptr::null())
      |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`

This is a clippy bug [1]: the lint decides whether an expression is
equivalent to `Default::default()` by inspecting the optimized MIR of
`<*const T as Default>::default` exported by `core`, so its outcome
depends on the optimization level `core` was built with. Moreover, its
suggestion ignores our MSRV of 1.85 (`Default` for `*const T` is only
stable since Rust 1.88), so we could not apply it anyway.

Disable the lint globally rather than working around this single
occurrence; it can be re-enabled conditionally using `rustc-min-version`
once clippy is fixed.

Link: https://github.com/rust-lang/rust-clippy/issues/17379
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Cc: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is pinned in older LTSs).
Link: https://patch.msgid.link/20260708-soc_unwrap_or-v2-1-007ed724cc7b@nvidia.com
[ Moved to non-versioned group. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Makefile

index b9c5792c79e0160b3c787f8a686bd60d9f8066d7..e54cc46340fd139b8852a577fead21627d177cbd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -475,6 +475,10 @@ KBUILD_USERLDFLAGS := $(USERLDFLAGS)
 
 # These flags apply to all Rust code in the tree, including the kernel and
 # host programs.
+#
+# `-Aclippy::unwrap_or_default`: the lint is buggy [1] and ignores our
+# MSRV. It can trigger depending on the optimization level.
+# [1] https://github.com/rust-lang/rust-clippy/issues/17379
 export rust_common_flags := --edition=2021 \
                            -Zbinary_dep_depinfo=y \
                            -Astable_features \
@@ -503,6 +507,7 @@ export rust_common_flags := --edition=2021 \
                            -Aclippy::uninlined_format_args \
                            -Wclippy::unnecessary_safety_comment \
                            -Wclippy::unnecessary_safety_doc \
+                           -Aclippy::unwrap_or_default \
                            -Wrustdoc::missing_crate_level_docs \
                            -Wrustdoc::unescaped_backticks