diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs index 0ec933e8784..d1213e5e5fd 100644 --- a/tests/ui/if_same_then_else.rs +++ b/tests/ui/if_same_then_else.rs @@ -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 = ""; diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr index b170db31b85..fa42afff0be 100644 --- a/tests/ui/if_same_then_else.stderr +++ b/tests/ui/if_same_then_else.stderr @@ -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 diff --git a/tests/ui/match_same_arms.rs b/tests/ui/match_same_arms.rs index baba4367fb4..880518b010a 100644 --- a/tests/ui/match_same_arms.rs +++ b/tests/ui/match_same_arms.rs @@ -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, diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index d7545fed586..42c6f910dc3 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -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 @@ -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 diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr index 27438258d23..232ae28009b 100644 --- a/tests/ui/matches.stderr +++ b/tests/ui/matches.stderr @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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