Skip to content

Commit 40f3665

Browse files
author
Vincent Dal Maso
committed
Fix breaking tests
Changes: - Fix stderr breaking the tests - Adding tests over the if arms
1 parent fa9f744 commit 40f3665

File tree

5 files changed

+79
-32
lines changed

5 files changed

+79
-32
lines changed

tests/ui/if_same_then_else.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ fn if_same_then_else() -> Result<&'static str, ()> {
232232
return Ok(&foo[0..]);
233233
}
234234

235+
if true {
236+
let foo = "";
237+
return Ok(&foo[0..]);
238+
} else if false {
239+
let foo = "bar";
240+
return Ok(&foo[0..]);
241+
} else if true {
242+
let foo = "";
243+
return Ok(&foo[0..]);
244+
} else {
245+
let foo = "";
246+
return Ok(&foo[0..]);
247+
}
248+
235249
// False positive `if_same_then_else`: `let (x, y)` vs. `let (y, x)`; see issue #3559.
236250
if true {
237251
let foo = "";

tests/ui/if_same_then_else.stderr

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,38 @@ LL | | try!(Ok("foo"));
210210
LL | | } else {
211211
| |_____^
212212

213-
error: aborting due to 10 previous errors
213+
error: this `if` has identical blocks
214+
--> $DIR/if_same_then_else.rs:244:12
215+
|
216+
LL | } else {
217+
| ____________^
218+
LL | | let foo = "";
219+
LL | | return Ok(&foo[0..]);
220+
LL | | }
221+
| |_____^
222+
|
223+
note: same as this
224+
--> $DIR/if_same_then_else.rs:241:20
225+
|
226+
LL | } else if true {
227+
| ____________________^
228+
LL | | let foo = "";
229+
LL | | return Ok(&foo[0..]);
230+
LL | | } else {
231+
| |_____^
232+
233+
error: this `if` has the same condition as a previous if
234+
--> $DIR/if_same_then_else.rs:241:15
235+
|
236+
LL | } else if true {
237+
| ^^^^
238+
|
239+
= note: #[deny(clippy::ifs_same_cond)] on by default
240+
note: same as this
241+
--> $DIR/if_same_then_else.rs:235:8
242+
|
243+
LL | if true {
244+
| ^^^^
245+
246+
error: aborting due to 12 previous errors
214247

tests/ui/match_same_arms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn match_same_arms() {
119119

120120
let _ = match 42 {
121121
1 => 2,
122-
2 => 2, //~ ERROR 2rd matched arms have same body
122+
2 => 2, //~ ERROR 2nd matched arms have same body
123123
3 => 2, //~ ERROR 3rd matched arms have same body
124124
4 => 3,
125125
_ => 0,

tests/ui/match_same_arms.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ LL | 41 => 2,
176176
error: this `match` has identical arm bodies
177177
--> $DIR/match_same_arms.rs:122:14
178178
|
179-
LL | 2 => 2, //~ ERROR 2rd matched arms have same body
179+
LL | 2 => 2, //~ ERROR 2nd matched arms have same body
180180
| ^
181181
|
182182
note: same as this
@@ -216,12 +216,12 @@ LL | 3 => 2, //~ ERROR 3rd matched arms have same body
216216
note: same as this
217217
--> $DIR/match_same_arms.rs:122:14
218218
|
219-
LL | 2 => 2, //~ ERROR 2rd matched arms have same body
219+
LL | 2 => 2, //~ ERROR 2nd matched arms have same body
220220
| ^
221221
help: consider refactoring into `2 | 3`
222222
--> $DIR/match_same_arms.rs:122:9
223223
|
224-
LL | 2 => 2, //~ ERROR 2rd matched arms have same body
224+
LL | 2 => 2, //~ ERROR 2nd matched arms have same body
225225
| ^
226226

227227
error: aborting due to 12 previous errors

tests/ui/matches.stderr

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ note: same as this
8989
|
9090
LL | Ok(3) => println!("ok"),
9191
| ^^^^^^^^^^^^^^
92-
note: consider refactoring into `Ok(3) | Ok(_)`
93-
--> $DIR/matches.rs:53:18
92+
help: consider refactoring into `Ok(3) | Ok(_)`
93+
--> $DIR/matches.rs:53:9
9494
|
9595
LL | Ok(3) => println!("ok"),
96-
| ^^^^^^^^^^^^^^
96+
| ^^^^^
9797
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
9898

9999
error: Err(_) will match all errors, maybe not a good idea
@@ -115,11 +115,11 @@ note: same as this
115115
|
116116
LL | Ok(3) => println!("ok"),
117117
| ^^^^^^^^^^^^^^
118-
note: consider refactoring into `Ok(3) | Ok(_)`
119-
--> $DIR/matches.rs:59:18
118+
help: consider refactoring into `Ok(3) | Ok(_)`
119+
--> $DIR/matches.rs:59:9
120120
|
121121
LL | Ok(3) => println!("ok"),
122-
| ^^^^^^^^^^^^^^
122+
| ^^^^^
123123
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
124124

125125
error: Err(_) will match all errors, maybe not a good idea
@@ -141,11 +141,11 @@ note: same as this
141141
|
142142
LL | Ok(3) => println!("ok"),
143143
| ^^^^^^^^^^^^^^
144-
note: consider refactoring into `Ok(3) | Ok(_)`
145-
--> $DIR/matches.rs:65:18
144+
help: consider refactoring into `Ok(3) | Ok(_)`
145+
--> $DIR/matches.rs:65:9
146146
|
147147
LL | Ok(3) => println!("ok"),
148-
| ^^^^^^^^^^^^^^
148+
| ^^^^^
149149
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
150150

151151
error: this `match` has identical arm bodies
@@ -159,11 +159,11 @@ note: same as this
159159
|
160160
LL | Ok(3) => println!("ok"),
161161
| ^^^^^^^^^^^^^^
162-
note: consider refactoring into `Ok(3) | Ok(_)`
163-
--> $DIR/matches.rs:74:18
162+
help: consider refactoring into `Ok(3) | Ok(_)`
163+
--> $DIR/matches.rs:74:9
164164
|
165165
LL | Ok(3) => println!("ok"),
166-
| ^^^^^^^^^^^^^^
166+
| ^^^^^
167167
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
168168

169169
error: this `match` has identical arm bodies
@@ -177,11 +177,11 @@ note: same as this
177177
|
178178
LL | Ok(3) => println!("ok"),
179179
| ^^^^^^^^^^^^^^
180-
note: consider refactoring into `Ok(3) | Ok(_)`
181-
--> $DIR/matches.rs:81:18
180+
help: consider refactoring into `Ok(3) | Ok(_)`
181+
--> $DIR/matches.rs:81:9
182182
|
183183
LL | Ok(3) => println!("ok"),
184-
| ^^^^^^^^^^^^^^
184+
| ^^^^^
185185
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
186186

187187
error: this `match` has identical arm bodies
@@ -195,11 +195,11 @@ note: same as this
195195
|
196196
LL | Ok(3) => println!("ok"),
197197
| ^^^^^^^^^^^^^^
198-
note: consider refactoring into `Ok(3) | Ok(_)`
199-
--> $DIR/matches.rs:87:18
198+
help: consider refactoring into `Ok(3) | Ok(_)`
199+
--> $DIR/matches.rs:87:9
200200
|
201201
LL | Ok(3) => println!("ok"),
202-
| ^^^^^^^^^^^^^^
202+
| ^^^^^
203203
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
204204

205205
error: this `match` has identical arm bodies
@@ -213,11 +213,11 @@ note: same as this
213213
|
214214
LL | Ok(3) => println!("ok"),
215215
| ^^^^^^^^^^^^^^
216-
note: consider refactoring into `Ok(3) | Ok(_)`
217-
--> $DIR/matches.rs:93:18
216+
help: consider refactoring into `Ok(3) | Ok(_)`
217+
--> $DIR/matches.rs:93:9
218218
|
219219
LL | Ok(3) => println!("ok"),
220-
| ^^^^^^^^^^^^^^
220+
| ^^^^^
221221
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
222222

223223
error: this `match` has identical arm bodies
@@ -231,11 +231,11 @@ note: same as this
231231
|
232232
LL | (Ok(x), Some(_)) => println!("ok {}", x),
233233
| ^^^^^^^^^^^^^^^^^^^^
234-
note: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))`
235-
--> $DIR/matches.rs:116:29
234+
help: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))`
235+
--> $DIR/matches.rs:116:9
236236
|
237237
LL | (Ok(x), Some(_)) => println!("ok {}", x),
238-
| ^^^^^^^^^^^^^^^^^^^^
238+
| ^^^^^^^^^^^^^^^^
239239
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
240240

241241
error: this `match` has identical arm bodies
@@ -249,11 +249,11 @@ note: same as this
249249
|
250250
LL | Ok(3) => println!("ok"),
251251
| ^^^^^^^^^^^^^^
252-
note: consider refactoring into `Ok(3) | Ok(_)`
253-
--> $DIR/matches.rs:131:18
252+
help: consider refactoring into `Ok(3) | Ok(_)`
253+
--> $DIR/matches.rs:131:9
254254
|
255255
LL | Ok(3) => println!("ok"),
256-
| ^^^^^^^^^^^^^^
256+
| ^^^^^
257257
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
258258

259259
error: you don't need to add `&` to all patterns

0 commit comments

Comments
 (0)