summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/let_underscore_lock.txt
blob: bd8217fb58b3c19dce8e06a2cbd8ddf2f5639f00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
### What it does
Checks for `let _ = sync_lock`.
This supports `mutex` and `rwlock` in `std::sync` and `parking_lot`.

### 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();
```