* [PATCH v2] rust: allow `clippy::unwrap_or_default` globally
@ 2026-07-08 10:49 Alexandre Courbot
2026-07-08 10:54 ` Miguel Ojeda
2026-07-09 21:51 ` Miguel Ojeda
0 siblings, 2 replies; 3+ messages in thread
From: Alexandre Courbot @ 2026-07-08 10:49 UTC (permalink / raw)
To: rust-for-linux, linux-kernel
Cc: Miguel Ojeda, Alexandre Courbot, Nathan Chancellor,
Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Onur Özkan, linux-kbuild
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 <ojeda@kernel.org>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
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/20260707-soc_unwrap_or-v1-1-1ca1757a259f@nvidia.com
To: Nathan Chancellor <nathan@kernel.org>
To: Nicolas Schier <nsc@kernel.org>
To: Miguel Ojeda <ojeda@kernel.org>
To: Boqun Feng <boqun@kernel.org>
To: Gary Guo <gary@garyguo.net>
To: Björn Roy Baron <bjorn3_gh@protonmail.com>
To: Benno Lossin <lossin@kernel.org>
To: Andreas Hindborg <a.hindborg@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>
To: Trevor Gross <tmgross@umich.edu>
To: Danilo Krummrich <dakr@kernel.org>
To: Daniel Almeida <daniel.almeida@collabora.com>
To: Tamir Duberstein <tamird@kernel.org>
To: Alexandre Courbot <acourbot@nvidia.com>
To: Onur Özkan <work@onurozkan.dev>
Cc: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: rust-for-linux@vger.kernel.org
---
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 <acourbot@nvidia.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] rust: allow `clippy::unwrap_or_default` globally
2026-07-08 10:49 [PATCH v2] rust: allow `clippy::unwrap_or_default` globally Alexandre Courbot
@ 2026-07-08 10:54 ` Miguel Ojeda
2026-07-09 21:51 ` Miguel Ojeda
1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2026-07-08 10:54 UTC (permalink / raw)
To: Alexandre Courbot
Cc: rust-for-linux, linux-kernel, Miguel Ojeda, Nathan Chancellor,
Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Onur Özkan, linux-kbuild
On Wed, Jul 8, 2026 at 12:49 PM Alexandre Courbot <acourbot@nvidia.com> wrote:
>
> +# `-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
I guess it may be per-version later on (i.e. when they fix it), but
for now, it can go into the main list above -- I can move it when I
apply it.
Thanks for the patch!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rust: allow `clippy::unwrap_or_default` globally
2026-07-08 10:49 [PATCH v2] rust: allow `clippy::unwrap_or_default` globally Alexandre Courbot
2026-07-08 10:54 ` Miguel Ojeda
@ 2026-07-09 21:51 ` Miguel Ojeda
1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2026-07-09 21:51 UTC (permalink / raw)
To: Alexandre Courbot
Cc: rust-for-linux, linux-kernel, Miguel Ojeda, Nathan Chancellor,
Nicolas Schier, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Onur Özkan, linux-kbuild
On Wed, Jul 8, 2026 at 12:49 PM Alexandre Courbot <acourbot@nvidia.com> wrote:
>
> 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 <ojeda@kernel.org>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Applied to `rust-fixes` -- thanks!
Cc: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is
pinned in older LTSs).
[ Moved to non-versioned group. - Miguel ]
Cheers,
Miguel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-09 21:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 10:49 [PATCH v2] rust: allow `clippy::unwrap_or_default` globally Alexandre Courbot
2026-07-08 10:54 ` Miguel Ojeda
2026-07-09 21:51 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox