From: Boqun Feng <boqun.feng@gmail.com>
To: Jason Devers <dev.json2@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@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@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
rust-for-linux@vger.kernel.org, boris.chen.czy@gmail.com
Subject: Re: [PATCH v6] rust: sync: add #[must_use] to Lock::try_lock
Date: Sun, 15 Dec 2024 12:05:01 -0800 [thread overview]
Message-ID: <Z182bbTgdGPEAb01@tardis.local> (raw)
In-Reply-To: <20241212154753.139563-1-dev.json2@gmail.com>
Hi Jason,
On Thu, Dec 12, 2024 at 10:47:53AM -0500, Jason Devers wrote:
> The `Lock::try_lock` function returns an `Option<Guard<...>>`, but it
> currently does not issue a warning if the return value is unused.
> To avoid potential bugs, the `#[must_use]` annotation is added to ensure proper usage.
>
> Note that `T` is `#[must_use]` but `Option<T>` is not.
> For more context, see: https://github.com/rust-lang/rust/issues/71368.
>
> Suggested-by: Alice Ryhl <aliceryhl@google.com>
> Link: https://github.com/Rust-for-Linux/linux/issues/1133
I think you could add Alice's Reviewed-by from the previous version:
https://lore.kernel.org/rust-for-linux/CAH5fLghjR4fctjoLT9Zom3drNMQ6vdE9hUTnZZ4Ms1qQHGFe=A@mail.gmail.com/
or you have any reason that you need another "Reviewed-by" tag?
(No need to send a new version, I'm just making sure you and Alice both
agree the "Reviewed-by" tag still applies to this patch.)
Regards,
Boqun
> Signed-off-by: Jason Devers <dev.json2@gmail.com>
> ---
> rust/kernel/sync/lock.rs | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
> index 41dcddac69e2..aacc227536cb 100644
> --- a/rust/kernel/sync/lock.rs
> +++ b/rust/kernel/sync/lock.rs
> @@ -147,6 +147,8 @@ pub fn lock(&self) -> Guard<'_, T, B> {
> /// Tries to acquire the lock.
> ///
> /// Returns a guard that can be used to access the data protected by the lock if successful.
> + // `Option<T>` is not `#[must_use]` even if `T` is, thus the attribute is needed here.
> + #[must_use = "if unused, the lock will be immediately unlocked"]
> pub fn try_lock(&self) -> Option<Guard<'_, T, B>> {
> // SAFETY: The constructor of the type calls `init`, so the existence of the object proves
> // that `init` was called.
> --
> 2.44.2
>
next prev parent reply other threads:[~2024-12-15 20:05 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-08 18:48 [PATCH] rust: sync: add #[must_use] to Lock::try_lock Jason Devers
2024-12-08 19:11 ` Boqun Feng
[not found] ` <CAOJvc-bi6ym6ZMAbDSh4H_L6LQXoTs8oNY07SZ1crzXxY9BodQ@mail.gmail.com>
2024-12-08 19:43 ` jos
2024-12-08 20:02 ` Boqun Feng
2024-12-08 20:50 ` Jason Devers
2024-12-08 21:57 ` Tamir Duberstein
2024-12-08 22:09 ` jos
2024-12-08 22:26 ` Jason Devers
2024-12-09 11:57 ` Miguel Ojeda
2024-12-09 17:09 ` jos
2024-12-11 2:05 ` [PATCH v4] " Jason Devers
2024-12-11 9:17 ` Alice Ryhl
2024-12-11 9:45 ` Miguel Ojeda
2024-12-11 17:05 ` jos
2024-12-11 18:57 ` Boqun Feng
2024-12-12 3:11 ` [PATCH v5] " Jason Devers
2024-12-12 11:25 ` Miguel Ojeda
2024-12-12 15:47 ` [PATCH v6] " Jason Devers
2024-12-15 20:05 ` Boqun Feng [this message]
2025-01-09 13:05 ` Alice Ryhl
2025-01-15 18:12 ` Boqun Feng
2025-07-19 17:40 ` [tip: locking/core] rust: sync: Add #[must_use] to Lock::try_lock() tip-bot2 for Jason Devers
2024-12-08 21:28 ` [PATCH] rust: sync: add #[must_use] to Lock::try_lock Miguel Ojeda
2024-12-09 7:11 ` Alice Ryhl
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=Z182bbTgdGPEAb01@tardis.local \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boris.chen.czy@gmail.com \
--cc=dev.json2@gmail.com \
--cc=gary@garyguo.net \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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.