summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/equatable_if_let.txt
blob: 9997046954c20d3779fe82a2384579dfc6ca8be0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
### What it does
Checks for pattern matchings that can be expressed using equality.

### Why is this bad?

* It reads better and has less cognitive load because equality won't cause binding.
* It is a [Yoda condition](https://en.wikipedia.org/wiki/Yoda_conditions). Yoda conditions are widely
criticized for increasing the cognitive load of reading the code.
* Equality is a simple bool expression and can be merged with `&&` and `||` and
reuse if blocks

### Example
```
if let Some(2) = x {
    do_thing();
}
```
Use instead:
```
if x == Some(2) {
    do_thing();
}
```