Skip to content

Commit

Permalink
Fix breaking tests
Browse files Browse the repository at this point in the history
Changes:
- Fix stderr breaking the tests
- Adding tests over the if arms
  • Loading branch information
Vincent Dal Maso committed May 21, 2019
1 parent fa9f744 commit 40f3665
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 32 deletions.
14 changes: 14 additions & 0 deletions tests/ui/if_same_then_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ fn if_same_then_else() -> Result<&'static str, ()> {
return Ok(&foo[0..]);
}

if true {
let foo = "";
return Ok(&foo[0..]);
} else if false {
let foo = "bar";
return Ok(&foo[0..]);
} else if true {
let foo = "";
return Ok(&foo[0..]);
} else {
let foo = "";
return Ok(&foo[0..]);
}

// False positive `if_same_then_else`: `let (x, y)` vs. `let (y, x)`; see issue #3559.
if true {
let foo = "";
Expand Down
35 changes: 34 additions & 1 deletion tests/ui/if_same_then_else.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,38 @@ LL | | try!(Ok("foo"));
LL | | } else {
| |_____^

error: aborting due to 10 previous errors
error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:244:12
|
LL | } else {
| ____________^
LL | | let foo = "";
LL | | return Ok(&foo[0..]);
LL | | }
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:241:20
|
LL | } else if true {
| ____________________^
LL | | let foo = "";
LL | | return Ok(&foo[0..]);
LL | | } else {
| |_____^

error: this `if` has the same condition as a previous if
--> $DIR/if_same_then_else.rs:241:15
|
LL | } else if true {
| ^^^^
|
= note: #[deny(clippy::ifs_same_cond)] on by default
note: same as this
--> $DIR/if_same_then_else.rs:235:8
|
LL | if true {
| ^^^^

error: aborting due to 12 previous errors

2 changes: 1 addition & 1 deletion tests/ui/match_same_arms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn match_same_arms() {

let _ = match 42 {
1 => 2,
2 => 2, //~ ERROR 2rd matched arms have same body
2 => 2, //~ ERROR 2nd matched arms have same body
3 => 2, //~ ERROR 3rd matched arms have same body
4 => 3,
_ => 0,
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/match_same_arms.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ LL | 41 => 2,
error: this `match` has identical arm bodies
--> $DIR/match_same_arms.rs:122:14
|
LL | 2 => 2, //~ ERROR 2rd matched arms have same body
LL | 2 => 2, //~ ERROR 2nd matched arms have same body
| ^
|
note: same as this
Expand Down Expand Up @@ -216,12 +216,12 @@ LL | 3 => 2, //~ ERROR 3rd matched arms have same body
note: same as this
--> $DIR/match_same_arms.rs:122:14
|
LL | 2 => 2, //~ ERROR 2rd matched arms have same body
LL | 2 => 2, //~ ERROR 2nd matched arms have same body
| ^
help: consider refactoring into `2 | 3`
--> $DIR/match_same_arms.rs:122:9
|
LL | 2 => 2, //~ ERROR 2rd matched arms have same body
LL | 2 => 2, //~ ERROR 2nd matched arms have same body
| ^

error: aborting due to 12 previous errors
Expand Down
54 changes: 27 additions & 27 deletions tests/ui/matches.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ note: same as this
|
LL | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
note: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:53:18
help: consider refactoring into `Ok(3) | Ok(_)`
--> $DIR/matches.rs:53:9
|
LL | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^
| ^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

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

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

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

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

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

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

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

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

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

0 comments on commit 40f3665

Please sign in to comment.