]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/mutex_atomic.txt
Rollup merge of #101189 - daxpedda:ready-into-inner, r=joshtriplett
[rust.git] / src / tools / clippy / src / docs / mutex_atomic.txt
1 ### What it does
2 Checks for usages of `Mutex<X>` where an atomic will do.
3
4 ### Why is this bad?
5 Using a mutex just to make access to a plain bool or
6 reference sequential is shooting flies with cannons.
7 `std::sync::atomic::AtomicBool` and `std::sync::atomic::AtomicPtr` are leaner and
8 faster.
9
10 ### Known problems
11 This lint cannot detect if the mutex is actually used
12 for waiting before a critical section.
13
14 ### Example
15 ```
16 let x = Mutex::new(&y);
17 ```
18
19 Use instead:
20 ```
21 let x = AtomicBool::new(y);
22 ```