Re: [PATCH] rust: Add #[must_use] to Lock::try_lock, GlobalLock::try_lock, and XArray::try_lock

From: Alice Ryhl
Date: Mon Jul 21 2025 - 07:06:31 EST


On Fri, Jul 18, 2025 at 4:20 PM TruongSinh Tran-Nguyen <i@xxxxxxxxxxxxxx> wrote:
>
> These methods return an RAII guard that unlocks the lock when dropped.
> If the return value is ignored, the lock is released immediately,
> which is likely not the intended behavior.
>
> This addresses issue #1133 in the rust-for-linux project.
>
> Signed-off-by: TruongSinh Tran-Nguyen <i@xxxxxxxxxxxxxx>

I like the reason string that the previous patch used:
if unused, the lock will be immediately unlocked

Perhaps we could update this to use that wording for the remaining
try_lock methods?

Alice