* [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
@ 2026-07-07 10:12 Alexandre Courbot
2026-07-07 11:11 ` Onur Özkan
2026-07-07 11:43 ` Gary Guo
0 siblings, 2 replies; 10+ messages in thread
From: Alexandre Courbot @ 2026-07-07 10:12 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Daniel Almeida, Tamir Duberstein, Onur Özkan, Matthew Maurer
Cc: driver-core, rust-for-linux, linux-kernel, Alexandre Courbot
The `clippy::unwrap_or_default` warning triggers on
`rust/kernel/soc.rs` since rustc 1.88:
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()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#unwrap_or_default
= note: `-W clippy::unwrap-or-default` implied by `-W clippy::all`
= help: to override `-W clippy::all` add `#[allow(clippy::unwrap_or_default)]`
Since our current MSRV is 1.85, we cannot fix the warning as
recommended, so allow the lint on the `cstring_to_c` function instead.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
rust/kernel/soc.rs | 3 +++
1 file changed, 3 insertions(+)
diff --git a/rust/kernel/soc.rs b/rust/kernel/soc.rs
index 0d6a36c83cb6..7998962560f8 100644
--- a/rust/kernel/soc.rs
+++ b/rust/kernel/soc.rs
@@ -60,6 +60,9 @@ struct BuiltAttributes {
inner: Opaque<bindings::soc_device_attribute>,
}
+// `unwrap_or_default()` on a raw pointer requires `Default for *const T`, which is stable since
+// Rust 1.88. Remove when the MSRV allows it.
+#[allow(clippy::unwrap_or_default)]
fn cstring_to_c(mcs: &Option<CString>) -> *const kernel::ffi::c_char {
mcs.as_ref()
.map(|cs| cs.as_char_ptr())
---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260707-soc_unwrap_or-ed37e674a759
Best regards,
--
Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
2026-07-07 10:12 [PATCH] rust: soc: silence clippy warning with rustc >= 1.88 Alexandre Courbot
@ 2026-07-07 11:11 ` Onur Özkan
2026-07-07 11:43 ` Gary Guo
1 sibling, 0 replies; 10+ messages in thread
From: Onur Özkan @ 2026-07-07 11:11 UTC (permalink / raw)
To: Alexandre Courbot
Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Daniel Almeida, Tamir Duberstein, Matthew Maurer, driver-core,
rust-for-linux, linux-kernel
On Tue, 07 Jul 2026 19:12:21 +0900
Alexandre Courbot <acourbot@nvidia.com> wrote:
> The `clippy::unwrap_or_default` warning triggers on
> `rust/kernel/soc.rs` since rustc 1.88:
>
> 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()`
> |
> = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#unwrap_or_default
> = note: `-W clippy::unwrap-or-default` implied by `-W clippy::all`
> = help: to override `-W clippy::all` add `#[allow(clippy::unwrap_or_default)]`
>
> Since our current MSRV is 1.85, we cannot fix the warning as
> recommended, so allow the lint on the `cstring_to_c` function instead.
>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
> rust/kernel/soc.rs | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/rust/kernel/soc.rs b/rust/kernel/soc.rs
> index 0d6a36c83cb6..7998962560f8 100644
> --- a/rust/kernel/soc.rs
> +++ b/rust/kernel/soc.rs
> @@ -60,6 +60,9 @@ struct BuiltAttributes {
> inner: Opaque<bindings::soc_device_attribute>,
> }
>
> +// `unwrap_or_default()` on a raw pointer requires `Default for *const T`, which is stable since
> +// Rust 1.88. Remove when the MSRV allows it.
I would move "Remove when the MSRV allows it." to the next line as TODO.
Regards,
Onur
> +#[allow(clippy::unwrap_or_default)]
> fn cstring_to_c(mcs: &Option<CString>) -> *const kernel::ffi::c_char {
> mcs.as_ref()
> .map(|cs| cs.as_char_ptr())
>
> ---
> base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
> change-id: 20260707-soc_unwrap_or-ed37e674a759
>
> Best regards,
> --
> Alexandre Courbot <acourbot@nvidia.com>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
2026-07-07 10:12 [PATCH] rust: soc: silence clippy warning with rustc >= 1.88 Alexandre Courbot
2026-07-07 11:11 ` Onur Özkan
@ 2026-07-07 11:43 ` Gary Guo
2026-07-07 12:12 ` Alexandre Courbot
2026-07-07 12:12 ` Miguel Ojeda
1 sibling, 2 replies; 10+ messages in thread
From: Gary Guo @ 2026-07-07 11:43 UTC (permalink / raw)
To: Alexandre Courbot, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Daniel Almeida, Tamir Duberstein, Onur Özkan,
Matthew Maurer
Cc: driver-core, rust-for-linux, linux-kernel
On Tue Jul 7, 2026 at 11:12 AM BST, Alexandre Courbot wrote:
> The `clippy::unwrap_or_default` warning triggers on
> `rust/kernel/soc.rs` since rustc 1.88:
>
> 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()`
> |
> = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#unwrap_or_default
> = note: `-W clippy::unwrap-or-default` implied by `-W clippy::all`
> = help: to override `-W clippy::all` add `#[allow(clippy::unwrap_or_default)]`
>
> Since our current MSRV is 1.85, we cannot fix the warning as
> recommended, so allow the lint on the `cstring_to_c` function instead.
We set `msrv = "1.85"` in our .clippy.toml, and my local testing with 1.88 and
1.96.1 doesn't produce this warning.
Best,
Gary
>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
> rust/kernel/soc.rs | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/rust/kernel/soc.rs b/rust/kernel/soc.rs
> index 0d6a36c83cb6..7998962560f8 100644
> --- a/rust/kernel/soc.rs
> +++ b/rust/kernel/soc.rs
> @@ -60,6 +60,9 @@ struct BuiltAttributes {
> inner: Opaque<bindings::soc_device_attribute>,
> }
>
> +// `unwrap_or_default()` on a raw pointer requires `Default for *const T`, which is stable since
> +// Rust 1.88. Remove when the MSRV allows it.
> +#[allow(clippy::unwrap_or_default)]
> fn cstring_to_c(mcs: &Option<CString>) -> *const kernel::ffi::c_char {
> mcs.as_ref()
> .map(|cs| cs.as_char_ptr())
>
> ---
> base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
> change-id: 20260707-soc_unwrap_or-ed37e674a759
>
> Best regards,
> --
> Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
2026-07-07 11:43 ` Gary Guo
@ 2026-07-07 12:12 ` Alexandre Courbot
2026-07-07 12:12 ` Miguel Ojeda
1 sibling, 0 replies; 10+ messages in thread
From: Alexandre Courbot @ 2026-07-07 12:12 UTC (permalink / raw)
To: Gary Guo
Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Onur Özkan, Matthew Maurer, driver-core,
rust-for-linux, linux-kernel
On Tue Jul 7, 2026 at 8:43 PM JST, Gary Guo wrote:
> On Tue Jul 7, 2026 at 11:12 AM BST, Alexandre Courbot wrote:
>> The `clippy::unwrap_or_default` warning triggers on
>> `rust/kernel/soc.rs` since rustc 1.88:
>>
>> 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()`
>> |
>> = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#unwrap_or_default
>> = note: `-W clippy::unwrap-or-default` implied by `-W clippy::all`
>> = help: to override `-W clippy::all` add `#[allow(clippy::unwrap_or_default)]`
>>
>> Since our current MSRV is 1.85, we cannot fix the warning as
>> recommended, so allow the lint on the `cstring_to_c` function instead.
>
> We set `msrv = "1.85"` in our .clippy.toml, and my local testing with 1.88 and
> 1.96.1 doesn't produce this warning.
Then I guess we will want to understand why I am getting this warning
locally. I'd also expect the `msrv = "1.85"` to prevent this from
happening.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
2026-07-07 11:43 ` Gary Guo
2026-07-07 12:12 ` Alexandre Courbot
@ 2026-07-07 12:12 ` Miguel Ojeda
2026-07-07 14:19 ` Alexandre Courbot
1 sibling, 1 reply; 10+ messages in thread
From: Miguel Ojeda @ 2026-07-07 12:12 UTC (permalink / raw)
To: Gary Guo
Cc: Alexandre Courbot, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich, Miguel Ojeda, Boqun Feng, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Daniel Almeida, Tamir Duberstein, Onur Özkan, Matthew Maurer,
driver-core, rust-for-linux, linux-kernel
On Tue, Jul 7, 2026 at 1:43 PM Gary Guo <gary@garyguo.net> wrote:
>
> We set `msrv = "1.85"` in our .clippy.toml, and my local testing with 1.88 and
> 1.96.1 doesn't produce this warning.
Yeah, I was trying to reproduce it locally too and didn't succeed yet.
If it does reproduce somehow (e.g. a particular toolchain), then we
probably want:
Cc: stable@vger.kernel.org
Fixes: 057d44b05775 ("rust: Add soc_device support")
Cheers,
Miguel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
2026-07-07 12:12 ` Miguel Ojeda
@ 2026-07-07 14:19 ` Alexandre Courbot
2026-07-07 14:30 ` Gary Guo
0 siblings, 1 reply; 10+ messages in thread
From: Alexandre Courbot @ 2026-07-07 14:19 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Gary Guo, Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Onur Özkan, Matthew Maurer, driver-core,
rust-for-linux, linux-kernel
On Tue Jul 7, 2026 at 9:12 PM JST, Miguel Ojeda wrote:
> On Tue, Jul 7, 2026 at 1:43 PM Gary Guo <gary@garyguo.net> wrote:
>>
>> We set `msrv = "1.85"` in our .clippy.toml, and my local testing with 1.88 and
>> 1.96.1 doesn't produce this warning.
>
> Yeah, I was trying to reproduce it locally too and didn't succeed yet.
Ok so this is nuts but it appears to only reproduce when
`CONFIG_CC_OPTIMIZE_FOR_SIZE=y` (and `CONFIG_SAMPLE_RUST_SOC=m` to build
`soc.rs`)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
2026-07-07 14:19 ` Alexandre Courbot
@ 2026-07-07 14:30 ` Gary Guo
2026-07-08 8:25 ` Alexandre Courbot
0 siblings, 1 reply; 10+ messages in thread
From: Gary Guo @ 2026-07-07 14:30 UTC (permalink / raw)
To: Alexandre Courbot, Miguel Ojeda
Cc: Gary Guo, Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Onur Özkan, Matthew Maurer, driver-core,
rust-for-linux, linux-kernel
On Tue Jul 7, 2026 at 3:19 PM BST, Alexandre Courbot wrote:
> On Tue Jul 7, 2026 at 9:12 PM JST, Miguel Ojeda wrote:
>> On Tue, Jul 7, 2026 at 1:43 PM Gary Guo <gary@garyguo.net> wrote:
>>>
>>> We set `msrv = "1.85"` in our .clippy.toml, and my local testing with 1.88 and
>>> 1.96.1 doesn't produce this warning.
>>
>> Yeah, I was trying to reproduce it locally too and didn't succeed yet.
>
> Ok so this is nuts but it appears to only reproduce when
> `CONFIG_CC_OPTIMIZE_FOR_SIZE=y` (and `CONFIG_SAMPLE_RUST_SOC=m` to build
> `soc.rs`)
That's crazy. Turns out that clippy's default equivalent check relies on MIR:
https://github.com/rust-lang/rust-clippy/blob/60f8c3a019cfda37e07de60e9cfd7ee77b290fb5/clippy_utils/src/lib.rs#L570
and somehow this check misses `null()` when opt level is high enough. There
isn't a check for MSRV in the trait impl.
Please report a clippy bug.
Best,
Gary
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
2026-07-07 14:30 ` Gary Guo
@ 2026-07-08 8:25 ` Alexandre Courbot
2026-07-08 9:04 ` Miguel Ojeda
0 siblings, 1 reply; 10+ messages in thread
From: Alexandre Courbot @ 2026-07-08 8:25 UTC (permalink / raw)
To: Gary Guo
Cc: Miguel Ojeda, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich, Miguel Ojeda, Boqun Feng, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Daniel Almeida, Tamir Duberstein, Onur Özkan, Matthew Maurer,
driver-core, rust-for-linux, linux-kernel
On Tue Jul 7, 2026 at 11:30 PM JST, Gary Guo wrote:
> On Tue Jul 7, 2026 at 3:19 PM BST, Alexandre Courbot wrote:
>> On Tue Jul 7, 2026 at 9:12 PM JST, Miguel Ojeda wrote:
>>> On Tue, Jul 7, 2026 at 1:43 PM Gary Guo <gary@garyguo.net> wrote:
>>>>
>>>> We set `msrv = "1.85"` in our .clippy.toml, and my local testing with 1.88 and
>>>> 1.96.1 doesn't produce this warning.
>>>
>>> Yeah, I was trying to reproduce it locally too and didn't succeed yet.
>>
>> Ok so this is nuts but it appears to only reproduce when
>> `CONFIG_CC_OPTIMIZE_FOR_SIZE=y` (and `CONFIG_SAMPLE_RUST_SOC=m` to build
>> `soc.rs`)
>
> That's crazy. Turns out that clippy's default equivalent check relies on MIR:
> https://github.com/rust-lang/rust-clippy/blob/60f8c3a019cfda37e07de60e9cfd7ee77b290fb5/clippy_utils/src/lib.rs#L570
> and somehow this check misses `null()` when opt level is high enough. There
> isn't a check for MSRV in the trait impl.
>
> Please report a clippy bug.
Done: https://github.com/rust-lang/rust-clippy/issues/17379
As for this patch, I guess we don't need it then?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
2026-07-08 8:25 ` Alexandre Courbot
@ 2026-07-08 9:04 ` Miguel Ojeda
2026-07-08 10:11 ` Alexandre Courbot
0 siblings, 1 reply; 10+ messages in thread
From: Miguel Ojeda @ 2026-07-08 9:04 UTC (permalink / raw)
To: Alexandre Courbot
Cc: Gary Guo, Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Onur Özkan, Matthew Maurer, driver-core,
rust-for-linux, linux-kernel
On Wed, Jul 8, 2026 at 10:25 AM Alexandre Courbot <acourbot@nvidia.com> wrote:
>
> Done: https://github.com/rust-lang/rust-clippy/issues/17379
>
> As for this patch, I guess we don't need it then?
Thanks a lot for taking the time to fill the issue! Linked to our usual list:
https://github.com/Rust-for-Linux/linux/issues/349
But why do you mean we don't need it? It is still reproducible within
our possible toolchains, right? Or did I misunderstand something? Or
do you mean it is fairly rare and thus maybe not needed?
We can also always just disable that particular lint, and perhaps
later on re-enable it conditionally when fixed -- we have support for
that now.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
2026-07-08 9:04 ` Miguel Ojeda
@ 2026-07-08 10:11 ` Alexandre Courbot
0 siblings, 0 replies; 10+ messages in thread
From: Alexandre Courbot @ 2026-07-08 10:11 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Gary Guo, Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Onur Özkan, Matthew Maurer, driver-core,
rust-for-linux, linux-kernel
On Wed Jul 8, 2026 at 6:04 PM JST, Miguel Ojeda wrote:
> On Wed, Jul 8, 2026 at 10:25 AM Alexandre Courbot <acourbot@nvidia.com> wrote:
>>
>> Done: https://github.com/rust-lang/rust-clippy/issues/17379
>>
>> As for this patch, I guess we don't need it then?
>
> Thanks a lot for taking the time to fill the issue! Linked to our usual list:
>
> https://github.com/Rust-for-Linux/linux/issues/349
>
> But why do you mean we don't need it? It is still reproducible within
> our possible toolchains, right? Or did I misunderstand something? Or
> do you mean it is fairly rare and thus maybe not needed?
I mean that both the code and clippy setting are properly set, so
using a workaround for this particular occurrence seems like a
half-measure, as the problem can very well arise somewhere else.
>
> We can also always just disable that particular lint, and perhaps
> later on re-enable it conditionally when fixed -- we have support for
> that now.
That sounds like a better way to address this, yes.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-07-08 10:11 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07 10:12 [PATCH] rust: soc: silence clippy warning with rustc >= 1.88 Alexandre Courbot
2026-07-07 11:11 ` Onur Özkan
2026-07-07 11:43 ` Gary Guo
2026-07-07 12:12 ` Alexandre Courbot
2026-07-07 12:12 ` Miguel Ojeda
2026-07-07 14:19 ` Alexandre Courbot
2026-07-07 14:30 ` Gary Guo
2026-07-08 8:25 ` Alexandre Courbot
2026-07-08 9:04 ` Miguel Ojeda
2026-07-08 10:11 ` Alexandre Courbot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox