summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/match_same_arms.txt
blob: 14edf12032e0d31082449e2672ac8840f7c8fff8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
### What it does
Checks for `match` with identical arm bodies.

### Why is this bad?
This is probably a copy & paste error. If arm bodies
are the same on purpose, you can factor them
[using `|`](https://doc.rust-lang.org/book/patterns.html#multiple-patterns).

### Known problems
False positive possible with order dependent `match`
(see issue
[#860](https://github.com/rust-lang/rust-clippy/issues/860)).

### Example
```
match foo {
    Bar => bar(),
    Quz => quz(),
    Baz => bar(), // <= oops
}
```

This should probably be
```
match foo {
    Bar => bar(),
    Quz => quz(),
    Baz => baz(), // <= fixed
}
```

or if the original code was not a typo:
```
match foo {
    Bar | Baz => bar(), // <= shows the intent better
    Quz => quz(),
}
```