[PATCH v2] rust: allow `clippy::unwrap_or_default` globally
Alexandre Courbot <[email protected]> Wed, 08 Jul 2026 19:49:26 +0900
| Newsgroups | org.kernel.vger.linux-kbuild,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
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 [1]
Suggested-by: Miguel Ojeda <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
---
Changes in v2:
- Disable the `clippy::unwrap_or_default` lint globally instead of
allowing it on the site triggering the issue.
- Link to v1: https://patch.msgid.link/[email protected]
To: Nathan Chancellor <[email protected]>
To: Nicolas Schier <[email protected]>
To: Miguel Ojeda <[email protected]>
To: Boqun Feng <[email protected]>
To: Gary Guo <[email protected]>
To: Björn Roy Baron <[email protected]>
To: Benno Lossin <[email protected]>
To: Andreas Hindborg <[email protected]>
To: Alice Ryhl <[email protected]>
To: Trevor Gross <[email protected]>
To: Danilo Krummrich <[email protected]>
To: Daniel Almeida <[email protected]>
To: Tamir Duberstein <[email protected]>
To: Alexandre Courbot <[email protected]>
To: Onur Özkan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
Makefile | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index b9c5792c79e0..22be861c5e7d 100644
--- a/Makefile
+++ b/Makefile
@@ -863,8 +863,13 @@ export WARN_ON_UNUSED_TRACEPOINTS
# include bitmasking and shift operations. However, because it generated
# many hits, in Rust 1.86.0 it was split into a new `precedence_bits`
# lint which is not enabled by default.
+#
+# `-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
rust_common_flags_per_version := \
- $(if $(call rustc-min-version,108600),,-Aclippy::precedence)
+ $(if $(call rustc-min-version,108600),,-Aclippy::precedence) \
+ -Aclippy::unwrap_or_default
rust_common_flags += $(rust_common_flags_per_version)
KBUILD_HOSTRUSTFLAGS += $(rust_common_flags_per_version) $(HOSTRUSTFLAGS)
---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260707-soc_unwrap_or-ed37e674a759
Best regards,
--
Alexandre Courbot <[email protected]>