All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miguel Ojeda <ojeda@kernel.org>
To: Miguel Ojeda <ojeda@kernel.org>,
	Wedson Almeida Filho <wedsonaf@gmail.com>,
	Alex Gaynor <alex.gaynor@gmail.com>
Cc: "Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@lists.linux.dev
Subject: [PATCH 1/3] rust: sync: implement `Default` for `LockClassKey`
Date: Mon,  1 Apr 2024 23:23:01 +0200	[thread overview]
Message-ID: <20240401212303.537355-2-ojeda@kernel.org> (raw)
In-Reply-To: <20240401212303.537355-1-ojeda@kernel.org>

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


  reply	other threads:[~2024-04-01 21:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01 21:23 [PATCH 0/3] Rust 1.78.0 upgrade Miguel Ojeda
2024-04-01 21:23 ` Miguel Ojeda [this message]
2024-04-01 22:26   ` [PATCH 1/3] rust: sync: implement `Default` for `LockClassKey` Boqun Feng
2024-04-02  9:46   ` Alice Ryhl
2024-04-02 23:12   ` Benno Lossin
2024-04-01 21:23 ` [PATCH 2/3] rust: kernel: remove redundant imports Miguel Ojeda
2024-04-02  9:48   ` Alice Ryhl
2024-04-01 21:23 ` [PATCH 3/3] rust: upgrade to Rust 1.78.0 Miguel Ojeda
2024-04-01 21:52   ` Miguel Ojeda
2024-04-04 12:41   ` Alice Ryhl
2024-05-05 22:33 ` [PATCH 0/3] Rust 1.78.0 upgrade Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240401212303.537355-2-ojeda@kernel.org \
    --to=ojeda@kernel.org \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.