mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
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:
parent
902726c38d
commit
bfb230369e
@ -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() {}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user