RS.CLIPPY.IF_LET_MUTEX

Locking a `Mutex` in an `if let` block can cause deadlocks

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

What it does

Checks for Mutex::lock calls in if let expression with lock calls in any of the else blocks.

Disabled starting in Edition 2024

This lint is effectively disabled starting in Edition 2024 as if let ... else scoping was reworked such that this is no longer an issue. See Proposal: stabilize if_let_rescope for Edition 2024

Why is this bad?

The Mutex lock remains held for the whole if let ... else block and deadlocks.

Example

if let Ok(thing) = mutex.lock() {
    do_thing();
} else {
    mutex.lock();
}

Should be written

let locked = mutex.lock();
if let Ok(thing) = locked {
    do_thing(thing);
} else {
    use_locked(locked);
}