Re: [PATCH] rust: soc: silence clippy warning with rustc >= 1.88
From: Onur Özkan
Date: Tue Jul 07 2026 - 07:17:04 EST
On Tue, 07 Jul 2026 19:12:21 +0900
Alexandre Courbot <acourbot@xxxxxxxxxx> 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@xxxxxxxxxx>
> ---
> 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@xxxxxxxxxx>
>