]> git.lizzy.rs Git - rust.git/blob - src/docs/equatable_if_let.txt
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
[rust.git] / src / docs / equatable_if_let.txt
1 ### What it does
2 Checks for pattern matchings that can be expressed using equality.
3
4 ### Why is this bad?
5
6 * It reads better and has less cognitive load because equality won't cause binding.
7 * It is a [Yoda condition](https://en.wikipedia.org/wiki/Yoda_conditions). Yoda conditions are widely
8 criticized for increasing the cognitive load of reading the code.
9 * Equality is a simple bool expression and can be merged with `&&` and `||` and
10 reuse if blocks
11
12 ### Example
13 ```
14 if let Some(2) = x {
15     do_thing();
16 }
17 ```
18 Use instead:
19 ```
20 if x == Some(2) {
21     do_thing();
22 }
23 ```