From: Ashutosh Desai Date: Sat, 2 May 2026 16:00:57 +0000 (+0000) Subject: rust: sync: add #[must_use] to GlobalGuard and GlobalLock::try_lock X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03e8578813157c74d9f7033bd797b3939f2facd6;p=thirdparty%2Flinux.git rust: sync: add #[must_use] to GlobalGuard and GlobalLock::try_lock 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 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 Signed-off-by: Ashutosh Desai Reviewed-by: Gary Guo Link: https://patch.msgid.link/20260502160057.3402896-1-ashutoshdesai993@gmail.com Signed-off-by: Miguel Ojeda --- diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global.rs index aecbdc34738fb..ec2dd84316fc5 100644 --- a/rust/kernel/sync/lock/global.rs +++ b/rust/kernel/sync/lock/global.rs @@ -85,6 +85,7 @@ impl GlobalLock { } /// Try to lock this global lock. + #[must_use = "if unused, the lock will be immediately unlocked"] #[inline] pub fn try_lock(&'static self) -> Option> { Some(GlobalGuard { @@ -96,6 +97,7 @@ impl GlobalLock { /// A guard for a [`GlobalLock`]. /// /// See [`global_lock!`] for examples. +#[must_use = "the lock unlocks immediately when the guard is unused"] pub struct GlobalGuard { inner: Guard<'static, B::Item, B::Backend>, }