Skip to content

Commit 8290cad

Browse files
committed
Add new tests with the same guards for the match_same_arms
1 parent 7b9f778 commit 8290cad

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

tests/ui/match_same_arms2.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ fn match_same_arms() {
6767
_ => (),
6868
}
6969

70+
// No warning because guards are different
71+
let _ = match Some(42) {
72+
Some(a) if a == 42 => a,
73+
Some(a) if a == 24 => a,
74+
Some(_) => 24,
75+
None => 0,
76+
};
77+
78+
let _ = match (Some(42), Some(42)) {
79+
(Some(a), None) if a == 42 => a,
80+
(None, Some(a)) if a == 42 => a, //~ ERROR: this match arm has an identical body to another arm
81+
_ => 0,
82+
};
83+
7084
match (Some(42), Some(42)) {
7185
(Some(a), ..) => bar(a), //~ ERROR: this match arm has an identical body to another arm
7286
(.., Some(a)) => bar(a),

tests/ui/match_same_arms2.stderr

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,22 @@ LL | (Some(a), None) => bar(a),
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^^
7272

7373
error: this match arm has an identical body to another arm
74-
--> $DIR/match_same_arms2.rs:71:9
74+
--> $DIR/match_same_arms2.rs:80:9
75+
|
76+
LL | (None, Some(a)) if a == 42 => a,
77+
| ---------------^^^^^^^^^^^^^^^^
78+
| |
79+
| help: try merging the arm patterns: `(None, Some(a)) | (Some(a), None)`
80+
|
81+
= help: or try changing either arm body
82+
note: other arm here
83+
--> $DIR/match_same_arms2.rs:79:9
84+
|
85+
LL | (Some(a), None) if a == 42 => a,
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
88+
error: this match arm has an identical body to another arm
89+
--> $DIR/match_same_arms2.rs:85:9
7590
|
7691
LL | (Some(a), ..) => bar(a),
7792
| -------------^^^^^^^^^^
@@ -80,13 +95,13 @@ LL | (Some(a), ..) => bar(a),
8095
|
8196
= help: or try changing either arm body
8297
note: other arm here
83-
--> $DIR/match_same_arms2.rs:72:9
98+
--> $DIR/match_same_arms2.rs:86:9
8499
|
85100
LL | (.., Some(a)) => bar(a),
86101
| ^^^^^^^^^^^^^^^^^^^^^^^
87102

88103
error: this match arm has an identical body to another arm
89-
--> $DIR/match_same_arms2.rs:105:9
104+
--> $DIR/match_same_arms2.rs:119:9
90105
|
91106
LL | (Ok(x), Some(_)) => println!("ok {}", x),
92107
| ----------------^^^^^^^^^^^^^^^^^^^^^^^^
@@ -95,13 +110,13 @@ LL | (Ok(x), Some(_)) => println!("ok {}", x),
95110
|
96111
= help: or try changing either arm body
97112
note: other arm here
98-
--> $DIR/match_same_arms2.rs:106:9
113+
--> $DIR/match_same_arms2.rs:120:9
99114
|
100115
LL | (Ok(_), Some(x)) => println!("ok {}", x),
101116
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102117

103118
error: this match arm has an identical body to another arm
104-
--> $DIR/match_same_arms2.rs:121:9
119+
--> $DIR/match_same_arms2.rs:135:9
105120
|
106121
LL | Ok(_) => println!("ok"),
107122
| -----^^^^^^^^^^^^^^^^^^
@@ -110,13 +125,13 @@ LL | Ok(_) => println!("ok"),
110125
|
111126
= help: or try changing either arm body
112127
note: other arm here
113-
--> $DIR/match_same_arms2.rs:120:9
128+
--> $DIR/match_same_arms2.rs:134:9
114129
|
115130
LL | Ok(3) => println!("ok"),
116131
| ^^^^^^^^^^^^^^^^^^^^^^^
117132

118133
error: this match arm has an identical body to another arm
119-
--> $DIR/match_same_arms2.rs:148:9
134+
--> $DIR/match_same_arms2.rs:162:9
120135
|
121136
LL | 1 => {
122137
| ^ help: try merging the arm patterns: `1 | 0`
@@ -129,15 +144,15 @@ LL | | },
129144
|
130145
= help: or try changing either arm body
131146
note: other arm here
132-
--> $DIR/match_same_arms2.rs:145:9
147+
--> $DIR/match_same_arms2.rs:159:9
133148
|
134149
LL | / 0 => {
135150
LL | | empty!(0);
136151
LL | | },
137152
| |_________^
138153

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

153168
error: this match arm has an identical body to another arm
154-
--> $DIR/match_same_arms2.rs:199:9
169+
--> $DIR/match_same_arms2.rs:213:9
155170
|
156171
LL | Foo::X(0) => 1,
157172
| ---------^^^^^
@@ -160,13 +175,13 @@ LL | Foo::X(0) => 1,
160175
|
161176
= help: or try changing either arm body
162177
note: other arm here
163-
--> $DIR/match_same_arms2.rs:201:9
178+
--> $DIR/match_same_arms2.rs:215:9
164179
|
165180
LL | Foo::Z(_) => 1,
166181
| ^^^^^^^^^^^^^^
167182

168183
error: this match arm has an identical body to another arm
169-
--> $DIR/match_same_arms2.rs:209:9
184+
--> $DIR/match_same_arms2.rs:223:9
170185
|
171186
LL | Foo::Z(_) => 1,
172187
| ---------^^^^^
@@ -175,13 +190,13 @@ LL | Foo::Z(_) => 1,
175190
|
176191
= help: or try changing either arm body
177192
note: other arm here
178-
--> $DIR/match_same_arms2.rs:207:9
193+
--> $DIR/match_same_arms2.rs:221:9
179194
|
180195
LL | Foo::X(0) => 1,
181196
| ^^^^^^^^^^^^^^
182197

183198
error: this match arm has an identical body to another arm
184-
--> $DIR/match_same_arms2.rs:232:9
199+
--> $DIR/match_same_arms2.rs:246:9
185200
|
186201
LL | Some(Bar { y: 0, x: 5, .. }) => 1,
187202
| ----------------------------^^^^^
@@ -190,13 +205,13 @@ LL | Some(Bar { y: 0, x: 5, .. }) => 1,
190205
|
191206
= help: or try changing either arm body
192207
note: other arm here
193-
--> $DIR/match_same_arms2.rs:229:9
208+
--> $DIR/match_same_arms2.rs:243:9
194209
|
195210
LL | Some(Bar { x: 0, y: 5, .. }) => 1,
196211
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
197212

198213
error: this match arm has an identical body to another arm
199-
--> $DIR/match_same_arms2.rs:246:9
214+
--> $DIR/match_same_arms2.rs:260:9
200215
|
201216
LL | 1 => cfg!(not_enable),
202217
| -^^^^^^^^^^^^^^^^^^^^
@@ -205,10 +220,10 @@ LL | 1 => cfg!(not_enable),
205220
|
206221
= help: or try changing either arm body
207222
note: other arm here
208-
--> $DIR/match_same_arms2.rs:245:9
223+
--> $DIR/match_same_arms2.rs:259:9
209224
|
210225
LL | 0 => cfg!(not_enable),
211226
| ^^^^^^^^^^^^^^^^^^^^^
212227

213-
error: aborting due to 13 previous errors
228+
error: aborting due to 14 previous errors
214229

0 commit comments

Comments
 (0)