Skip to content

Commit

Permalink
Add new tests with the same guards for the match_same_arms
Browse files Browse the repository at this point in the history
  • Loading branch information
roife committed Dec 30, 2023
1 parent 7b9f778 commit 8290cad
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
14 changes: 14 additions & 0 deletions tests/ui/match_same_arms2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ fn match_same_arms() {
_ => (),
}

// No warning because guards are different
let _ = match Some(42) {
Some(a) if a == 42 => a,
Some(a) if a == 24 => a,
Some(_) => 24,
None => 0,
};

let _ = match (Some(42), Some(42)) {
(Some(a), None) if a == 42 => a,
(None, Some(a)) if a == 42 => a, //~ ERROR: this match arm has an identical body to another arm
_ => 0,
};

match (Some(42), Some(42)) {
(Some(a), ..) => bar(a), //~ ERROR: this match arm has an identical body to another arm
(.., Some(a)) => bar(a),
Expand Down
51 changes: 33 additions & 18 deletions tests/ui/match_same_arms2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,22 @@ LL | (Some(a), None) => bar(a),
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:71:9
--> $DIR/match_same_arms2.rs:80:9
|
LL | (None, Some(a)) if a == 42 => a,
| ---------------^^^^^^^^^^^^^^^^
| |
| help: try merging the arm patterns: `(None, Some(a)) | (Some(a), None)`
|
= help: or try changing either arm body
note: other arm here
--> $DIR/match_same_arms2.rs:79:9
|
LL | (Some(a), None) if a == 42 => a,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:85:9
|
LL | (Some(a), ..) => bar(a),
| -------------^^^^^^^^^^
Expand All @@ -80,13 +95,13 @@ LL | (Some(a), ..) => bar(a),
|
= help: or try changing either arm body
note: other arm here
--> $DIR/match_same_arms2.rs:72:9
--> $DIR/match_same_arms2.rs:86:9
|
LL | (.., Some(a)) => bar(a),
| ^^^^^^^^^^^^^^^^^^^^^^^

error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:105:9
--> $DIR/match_same_arms2.rs:119:9
|
LL | (Ok(x), Some(_)) => println!("ok {}", x),
| ----------------^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -95,13 +110,13 @@ LL | (Ok(x), Some(_)) => println!("ok {}", x),
|
= help: or try changing either arm body
note: other arm here
--> $DIR/match_same_arms2.rs:106:9
--> $DIR/match_same_arms2.rs:120:9
|
LL | (Ok(_), Some(x)) => println!("ok {}", x),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:121:9
--> $DIR/match_same_arms2.rs:135:9
|
LL | Ok(_) => println!("ok"),
| -----^^^^^^^^^^^^^^^^^^
Expand All @@ -110,13 +125,13 @@ LL | Ok(_) => println!("ok"),
|
= help: or try changing either arm body
note: other arm here
--> $DIR/match_same_arms2.rs:120:9
--> $DIR/match_same_arms2.rs:134:9
|
LL | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^^^^^^^^^^

error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:148:9
--> $DIR/match_same_arms2.rs:162:9
|
LL | 1 => {
| ^ help: try merging the arm patterns: `1 | 0`
Expand All @@ -129,15 +144,15 @@ LL | | },
|
= help: or try changing either arm body
note: other arm here
--> $DIR/match_same_arms2.rs:145:9
--> $DIR/match_same_arms2.rs:159:9
|
LL | / 0 => {
LL | | empty!(0);
LL | | },
| |_________^

error: match expression looks like `matches!` macro
--> $DIR/match_same_arms2.rs:167:16
--> $DIR/match_same_arms2.rs:181:16
|
LL | let _ans = match x {
| ________________^
Expand All @@ -151,7 +166,7 @@ LL | | };
= help: to override `-D warnings` add `#[allow(clippy::match_like_matches_macro)]`

error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:199:9
--> $DIR/match_same_arms2.rs:213:9
|
LL | Foo::X(0) => 1,
| ---------^^^^^
Expand All @@ -160,13 +175,13 @@ LL | Foo::X(0) => 1,
|
= help: or try changing either arm body
note: other arm here
--> $DIR/match_same_arms2.rs:201:9
--> $DIR/match_same_arms2.rs:215:9
|
LL | Foo::Z(_) => 1,
| ^^^^^^^^^^^^^^

error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:209:9
--> $DIR/match_same_arms2.rs:223:9
|
LL | Foo::Z(_) => 1,
| ---------^^^^^
Expand All @@ -175,13 +190,13 @@ LL | Foo::Z(_) => 1,
|
= help: or try changing either arm body
note: other arm here
--> $DIR/match_same_arms2.rs:207:9
--> $DIR/match_same_arms2.rs:221:9
|
LL | Foo::X(0) => 1,
| ^^^^^^^^^^^^^^

error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:232:9
--> $DIR/match_same_arms2.rs:246:9
|
LL | Some(Bar { y: 0, x: 5, .. }) => 1,
| ----------------------------^^^^^
Expand All @@ -190,13 +205,13 @@ LL | Some(Bar { y: 0, x: 5, .. }) => 1,
|
= help: or try changing either arm body
note: other arm here
--> $DIR/match_same_arms2.rs:229:9
--> $DIR/match_same_arms2.rs:243:9
|
LL | Some(Bar { x: 0, y: 5, .. }) => 1,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:246:9
--> $DIR/match_same_arms2.rs:260:9
|
LL | 1 => cfg!(not_enable),
| -^^^^^^^^^^^^^^^^^^^^
Expand All @@ -205,10 +220,10 @@ LL | 1 => cfg!(not_enable),
|
= help: or try changing either arm body
note: other arm here
--> $DIR/match_same_arms2.rs:245:9
--> $DIR/match_same_arms2.rs:259:9
|
LL | 0 => cfg!(not_enable),
| ^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 13 previous errors
error: aborting due to 14 previous errors

0 comments on commit 8290cad

Please sign in to comment.