]> git.lizzy.rs Git - rust.git/blob - src/docs/unnested_or_patterns.txt
Add iter_kv_map lint
[rust.git] / src / docs / unnested_or_patterns.txt
1 ### What it does
2 Checks for unnested or-patterns, e.g., `Some(0) | Some(2)` and
3 suggests replacing the pattern with a nested one, `Some(0 | 2)`.
4
5 Another way to think of this is that it rewrites patterns in
6 *disjunctive normal form (DNF)* into *conjunctive normal form (CNF)*.
7
8 ### Why is this bad?
9 In the example above, `Some` is repeated, which unnecessarily complicates the pattern.
10
11 ### Example
12 ```
13 fn main() {
14     if let Some(0) | Some(2) = Some(0) {}
15 }
16 ```
17 Use instead:
18 ```
19 fn main() {
20     if let Some(0 | 2) = Some(0) {}
21 }
22 ```