Skip to content

Commit 03e8578

Browse files
geeky-ashuojeda
authored andcommitted
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<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@google.com> Signed-off-by: Ashutosh Desai <ashutoshdesai993@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260502160057.3402896-1-ashutoshdesai993@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 7594302 commit 03e8578

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

rust/kernel/sync/lock/global.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl<B: GlobalLockBackend> GlobalLock<B> {
8585
}
8686

8787
/// Try to lock this global lock.
88+
#[must_use = "if unused, the lock will be immediately unlocked"]
8889
#[inline]
8990
pub fn try_lock(&'static self) -> Option<GlobalGuard<B>> {
9091
Some(GlobalGuard {
@@ -96,6 +97,7 @@ impl<B: GlobalLockBackend> GlobalLock<B> {
9697
/// A guard for a [`GlobalLock`].
9798
///
9899
/// See [`global_lock!`] for examples.
100+
#[must_use = "the lock unlocks immediately when the guard is unused"]
99101
pub struct GlobalGuard<B: GlobalLockBackend> {
100102
inner: Guard<'static, B::Item, B::Backend>,
101103
}

0 commit comments

Comments
 (0)