In the upcoming Rust 1.78.0, Clippy suggests to implement `Default` even
when `new()` is `const`, since `Default::default()` may call `const`
functions even if it is not `const` itself [1]:
error: you should consider adding a `Default` implementation for `LockClassKey`
--> rust/kernel/sync.rs:31:5
|
31 | / pub const fn new() -> Self {
32 | | Self(Opaque::uninit())
33 | | }
| |_____^
Thus implement it.
Link: https://github.com/rust-lang/rust-clippy/pull/10903 [1]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
rust/kernel/sync.rs | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs
index c983f63fd56e..0ab20975a3b5 100644
--- a/rust/kernel/sync.rs
+++ b/rust/kernel/sync.rs
@@ -37,6 +37,12 @@ pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key {
}
}
+impl Default for LockClassKey {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
/// Defines a new static lock class and returns a pointer to it.
#[doc(hidden)]
#[macro_export]
--
2.44.0
On 01.04.24 23:23, Miguel Ojeda wrote:
> In the upcoming Rust 1.78.0, Clippy suggests to implement `Default` even
> when `new()` is `const`, since `Default::default()` may call `const`
> functions even if it is not `const` itself [1]:
>
> error: you should consider adding a `Default` implementation for `LockClassKey`
> --> rust/kernel/sync.rs:31:5
> |
> 31 | / pub const fn new() -> Self {
> 32 | | Self(Opaque::uninit())
> 33 | | }
> | |_____^
>
> Thus implement it.
>
> Link: https://github.com/rust-lang/rust-clippy/pull/10903 [1]
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> rust/kernel/sync.rs | 6 ++++++
> 1 file changed, 6 insertions(+)
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
--
Cheers,
Benno
On Mon, Apr 1, 2024 at 11:23 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> In the upcoming Rust 1.78.0, Clippy suggests to implement `Default` even
> when `new()` is `const`, since `Default::default()` may call `const`
> functions even if it is not `const` itself [1]:
>
> error: you should consider adding a `Default` implementation for `LockClassKey`
> --> rust/kernel/sync.rs:31:5
> |
> 31 | / pub const fn new() -> Self {
> 32 | | Self(Opaque::uninit())
> 33 | | }
> | |_____^
>
> Thus implement it.
>
> Link: https://github.com/rust-lang/rust-clippy/pull/10903 [1]
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
On Mon, Apr 01, 2024 at 11:23:01PM +0200, Miguel Ojeda wrote:
> In the upcoming Rust 1.78.0, Clippy suggests to implement `Default` even
> when `new()` is `const`, since `Default::default()` may call `const`
> functions even if it is not `const` itself [1]:
>
> error: you should consider adding a `Default` implementation for `LockClassKey`
> --> rust/kernel/sync.rs:31:5
> |
> 31 | / pub const fn new() -> Self {
> 32 | | Self(Opaque::uninit())
> 33 | | }
> | |_____^
>
> Thus implement it.
>
> Link: https://github.com/rust-lang/rust-clippy/pull/10903 [1]
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Regards,
Boqun
> ---
> rust/kernel/sync.rs | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs
> index c983f63fd56e..0ab20975a3b5 100644
> --- a/rust/kernel/sync.rs
> +++ b/rust/kernel/sync.rs
> @@ -37,6 +37,12 @@ pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key {
> }
> }
>
> +impl Default for LockClassKey {
> + fn default() -> Self {
> + Self::new()
> + }
> +}
> +
> /// Defines a new static lock class and returns a pointer to it.
> #[doc(hidden)]
> #[macro_export]
> --
> 2.44.0
>
© 2016 - 2026 Red Hat, Inc.