From 1be392ce4d521a79d46f80e5cdf8a745268375b0 Mon Sep 17 00:00:00 2001 From: Jason Devers Date: Sun, 8 Dec 2024 15:50:18 -0500 Subject: [PATCH] rust: sync: add #[must_use] to Lock::try_lock The `Lock::try_lock` function returns an `Option>`, 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. Suggested-by: Alice Ryhl Link: https://github.com/Rust-for-Linux/linux/issues/1133 Signed-off-by: Jason Devers --- rust/kernel/sync/lock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index 41dcddac69e203..f7d355c5d90a1b 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -147,6 +147,7 @@ impl Lock { /// Tries to acquire the lock. /// /// Returns a guard that can be used to access the data protected by the lock if successful. + #[must_use = "if unused, leading to an empty critical section"] pub fn try_lock(&self) -> Option> { // SAFETY: The constructor of the type calls `init`, so the existence of the object proves // that `init` was called.