]> git.lizzy.rs Git - rust.git/blob - src/docs/let_underscore_lock.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / let_underscore_lock.txt
1 ### What it does
2 Checks for `let _ = sync_lock`.
3 This supports `mutex` and `rwlock` in `std::sync` and `parking_lot`.
4
5 ### Why is this bad?
6 This statement immediately drops the lock instead of
7 extending its lifetime to the end of the scope, which is often not intended.
8 To extend lock lifetime to the end of the scope, use an underscore-prefixed
9 name instead (i.e. _lock). If you want to explicitly drop the lock,
10 `std::mem::drop` conveys your intention better and is less error-prone.
11
12 ### Example
13 ```
14 let _ = mutex.lock();
15 ```
16
17 Use instead:
18 ```
19 let _lock = mutex.lock();
20 ```