Skip to content

Commit bfb2303

Browse files
author
Vincent Dal Maso
committed
Add test for multiple same arms lints
Changes: - Add a test to match multiple arms in the same match statement
1 parent 902726c commit bfb2303

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed

tests/ui/match_same_arms.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ fn match_same_arms() {
108108
(None, Some(a)) => bar(a), // bindings have different types
109109
_ => (),
110110
}
111+
112+
let _ = match 42 {
113+
42 => 1,
114+
51 => 1, //~ ERROR match arms have same body
115+
41 => 2,
116+
52 => 2, //~ ERROR match arms have same body
117+
_ => 0,
118+
};
111119
}
112120

113121
fn main() {}

tests/ui/match_same_arms.stderr

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,10 @@
1-
error: this `match` has identical arm bodies
2-
--> $DIR/match_same_arms.rs:37:14
3-
|
4-
LL | _ => {
5-
| ______________^
6-
LL | | //~ ERROR match arms have same body
7-
LL | | foo();
8-
LL | | let mut a = 42 + [23].len() as i32;
9-
... |
10-
LL | | a
11-
LL | | },
12-
| |_________^
13-
|
14-
= note: `-D clippy::match-same-arms` implied by `-D warnings`
15-
note: same as this
16-
--> $DIR/match_same_arms.rs:28:15
17-
|
18-
LL | 42 => {
19-
| _______________^
20-
LL | | foo();
21-
LL | | let mut a = 42 + [23].len() as i32;
22-
LL | | if true {
23-
... |
24-
LL | | a
25-
LL | | },
26-
| |_________^
27-
note: `42` has the same arm body as the `_` wildcard, consider removing it`
28-
--> $DIR/match_same_arms.rs:28:15
29-
|
30-
LL | 42 => {
31-
| _______________^
32-
LL | | foo();
33-
LL | | let mut a = 42 + [23].len() as i32;
34-
LL | | if true {
35-
... |
36-
LL | | a
37-
LL | | },
38-
| |_________^
39-
401
error: this `match` has identical arm bodies
412
--> $DIR/match_same_arms.rs:52:14
423
|
434
LL | _ => 0, //~ ERROR match arms have same body
445
| ^
456
|
7+
= note: `-D clippy::match-same-arms` implied by `-D warnings`
468
note: same as this
479
--> $DIR/match_same_arms.rs:50:19
4810
|
@@ -139,5 +101,39 @@ note: consider refactoring into `(1, .., 3) | (.., 3)`
139101
LL | (1, .., 3) => 42,
140102
| ^^
141103

142-
error: aborting due to 7 previous errors
104+
error: this `match` has identical arm bodies
105+
--> $DIR/match_same_arms.rs:114:15
106+
|
107+
LL | 51 => 1, //~ ERROR match arms have same body
108+
| ^
109+
|
110+
note: same as this
111+
--> $DIR/match_same_arms.rs:113:15
112+
|
113+
LL | 42 => 1,
114+
| ^
115+
note: consider refactoring into `42 | 51`
116+
--> $DIR/match_same_arms.rs:113:15
117+
|
118+
LL | 42 => 1,
119+
| ^
120+
121+
error: this `match` has identical arm bodies
122+
--> $DIR/match_same_arms.rs:116:15
123+
|
124+
LL | 52 => 2, //~ ERROR match arms have same body
125+
| ^
126+
|
127+
note: same as this
128+
--> $DIR/match_same_arms.rs:115:15
129+
|
130+
LL | 41 => 2,
131+
| ^
132+
note: consider refactoring into `41 | 52`
133+
--> $DIR/match_same_arms.rs:115:15
134+
|
135+
LL | 41 => 2,
136+
| ^
137+
138+
error: aborting due to 8 previous errors
143139

0 commit comments

Comments
 (0)