Add test for multiple same arms lints

Changes:
- Add a test to match multiple arms in the same match statement
This commit is contained in:
Vincent Dal Maso 2019-05-16 14:13:57 +02:00
parent 902726c38d
commit bfb230369e
2 changed files with 44 additions and 40 deletions

View File

@ -108,6 +108,14 @@ fn match_same_arms() {
(None, Some(a)) => bar(a), // bindings have different types
_ => (),
}
let _ = match 42 {
42 => 1,
51 => 1, //~ ERROR match arms have same body
41 => 2,
52 => 2, //~ ERROR match arms have same body
_ => 0,
};
}
fn main() {}

View File

@ -1,48 +1,10 @@
error: this `match` has identical arm bodies
--> $DIR/match_same_arms.rs:37:14
|
LL | _ => {
| ______________^
LL | | //~ ERROR match arms have same body
LL | | foo();
LL | | let mut a = 42 + [23].len() as i32;
... |
LL | | a
LL | | },
| |_________^
|
= note: `-D clippy::match-same-arms` implied by `-D warnings`
note: same as this
--> $DIR/match_same_arms.rs:28:15
|
LL | 42 => {
| _______________^
LL | | foo();
LL | | let mut a = 42 + [23].len() as i32;
LL | | if true {
... |
LL | | a
LL | | },
| |_________^
note: `42` has the same arm body as the `_` wildcard, consider removing it`
--> $DIR/match_same_arms.rs:28:15
|
LL | 42 => {
| _______________^
LL | | foo();
LL | | let mut a = 42 + [23].len() as i32;
LL | | if true {
... |
LL | | a
LL | | },
| |_________^
error: this `match` has identical arm bodies
--> $DIR/match_same_arms.rs:52:14
|
LL | _ => 0, //~ ERROR match arms have same body
| ^
|
= note: `-D clippy::match-same-arms` implied by `-D warnings`
note: same as this
--> $DIR/match_same_arms.rs:50:19
|
@ -139,5 +101,39 @@ note: consider refactoring into `(1, .., 3) | (.., 3)`
LL | (1, .., 3) => 42,
| ^^
error: aborting due to 7 previous errors
error: this `match` has identical arm bodies
--> $DIR/match_same_arms.rs:114:15
|
LL | 51 => 1, //~ ERROR match arms have same body
| ^
|
note: same as this
--> $DIR/match_same_arms.rs:113:15
|
LL | 42 => 1,
| ^
note: consider refactoring into `42 | 51`
--> $DIR/match_same_arms.rs:113:15
|
LL | 42 => 1,
| ^
error: this `match` has identical arm bodies
--> $DIR/match_same_arms.rs:116:15
|
LL | 52 => 2, //~ ERROR match arms have same body
| ^
|
note: same as this
--> $DIR/match_same_arms.rs:115:15
|
LL | 41 => 2,
| ^
note: consider refactoring into `41 | 52`
--> $DIR/match_same_arms.rs:115:15
|
LL | 41 => 2,
| ^
error: aborting due to 8 previous errors