RS.CLIPPY.LET_UNDERSCORE_LOCK

Non-binding `let` on a synchronization lock

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: let_underscore_lock. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for let _ = sync_lock. This supports mutex and rwlock in parking_lot. For std locks see the rustc lint let_underscore_lock

Why is this bad?

This statement immediately drops the lock instead of extending its lifetime to the end of the scope, which is often not intended. To extend lock lifetime to the end of the scope, use an underscore-prefixed name instead (i.e. _lock). If you want to explicitly drop the lock, std::mem::drop conveys your intention better and is less error-prone.

Example

let _ = mutex.lock();

Use instead:

let _lock = mutex.lock();