Re: [PATCH] rust: sync: add #[must_use] to Lock::try_lock

Alice Ryhl
2024-12-09T07:11:38Z

On Sun, Dec 8, 2024 at 7:49 PM Jason Devers <dev.json2@gmail.com> wrote:
>
> The `Lock::try_lock` function returns an `Option<Guard<...>>`, but it
> currently does not issue a warning if the return value is unused. This
> could result in the lock being unlocked immediately, which is unsafe
> and unintended. This patch adds a `#[must_use]` annotation to
> `Lock::try_lock` to prevent this.

I agree that "unsafe" is the wrong word here. We can just say "which
is probably not what the user intended".

> Suggested-by: Alice Ryhl <alice@ryhl.io>

I use aliceryhl@google.com for kernel contributions.

> Link: https://github.com/Rust-for-Linux/linux/issues/1133
> Signed-off-by: Jason Devers <dev.json2@gmail.com>

Overall looks good to me! You may add:

Reviewed-by: Alice Ryhl <aliceryhl@google.com>