Re: [PATCH v2] rust: sync: add #[must_use] to GlobalGuard and GlobalLock::try_lock

From: Gary Guo

Date: Tue May 05 2026 - 08:45:05 EST


On Sat May 2, 2026 at 5:00 PM BST, Ashutosh Desai wrote:
> Guard is marked #[must_use] since dropping it releases the lock. GlobalGuard
> wraps Guard with identical semantics but was missing the annotation, so
> discarding it would silently compile without warning.
>
> Similarly, GlobalLock::try_lock was missing #[must_use]. Option<T> does not
> propagate #[must_use] from T, so the attribute needs to be on the function
> directly - same reason Lock::try_lock has it.
>
> Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> Signed-off-by: Ashutosh Desai <ashutoshdesai993@xxxxxxxxx>

Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>

> ---
> Changes in v2:
> - Remove explanatory comment above #[must_use] on try_lock (Alice Ryhl)
>
> Link to v1: https://lore.kernel.org/rust-for-linux/20260419001141.211935-1-ashutoshdesai993@xxxxxxxxx/
>
> rust/kernel/sync/lock/global.rs | 2 ++
> 1 file changed, 2 insertions(+)