diff --git a/tests/ui/copies.rs b/tests/ui/copies.rs index 8147edb98eb0..5db82006deaa 100644 --- a/tests/ui/copies.rs +++ b/tests/ui/copies.rs @@ -348,50 +348,6 @@ fn if_same_then_else() -> Result<&'static str, ()> { } } -#[warn(clippy::ifs_same_cond)] -#[allow(clippy::if_same_then_else)] // all empty blocks -fn ifs_same_cond() { - let a = 0; - let b = false; - - if b { - } else if b { - //~ ERROR ifs same condition - } - - if a == 1 { - } else if a == 1 { - //~ ERROR ifs same condition - } - - if 2 * a == 1 { - } else if 2 * a == 2 { - } else if 2 * a == 1 { - //~ ERROR ifs same condition - } else if a == 1 { - } - - // See #659 - if cfg!(feature = "feature1-659") { - 1 - } else if cfg!(feature = "feature2-659") { - 2 - } else { - 3 - }; - - let mut v = vec![1]; - if v.pop() == None { - // ok, functions - } else if v.pop() == None { - } - - if v.len() == 42 { - // ok, functions - } else if v.len() == 42 { - } -} - fn main() {} // Issue #2423. This was causing an ICE diff --git a/tests/ui/copies.stderr b/tests/ui/copies.stderr index 4c0bc4b01739..3fbc279b5374 100644 --- a/tests/ui/copies.stderr +++ b/tests/ui/copies.stderr @@ -351,42 +351,5 @@ LL | | try!(Ok("foo")); LL | | } else { | |_____^ -error: this `if` has the same condition as a previous if - --> $DIR/copies.rs:358:15 - | -LL | } else if b { - | ^ - | - = note: `-D clippy::ifs-same-cond` implied by `-D warnings` -note: same as this - --> $DIR/copies.rs:357:8 - | -LL | if b { - | ^ - -error: this `if` has the same condition as a previous if - --> $DIR/copies.rs:363:15 - | -LL | } else if a == 1 { - | ^^^^^^ - | -note: same as this - --> $DIR/copies.rs:362:8 - | -LL | if a == 1 { - | ^^^^^^ - -error: this `if` has the same condition as a previous if - --> $DIR/copies.rs:369:15 - | -LL | } else if 2 * a == 1 { - | ^^^^^^^^^^ - | -note: same as this - --> $DIR/copies.rs:367:8 - | -LL | if 2 * a == 1 { - | ^^^^^^^^^^ - -error: aborting due to 20 previous errors +error: aborting due to 17 previous errors diff --git a/tests/ui/ifs_same_cond.rs b/tests/ui/ifs_same_cond.rs new file mode 100644 index 000000000000..b67e730b9372 --- /dev/null +++ b/tests/ui/ifs_same_cond.rs @@ -0,0 +1,46 @@ +#![warn(clippy::ifs_same_cond)] +#![allow(clippy::if_same_then_else)] // all empty blocks + +fn ifs_same_cond() { + let a = 0; + let b = false; + + if b { + } else if b { + //~ ERROR ifs same condition + } + + if a == 1 { + } else if a == 1 { + //~ ERROR ifs same condition + } + + if 2 * a == 1 { + } else if 2 * a == 2 { + } else if 2 * a == 1 { + //~ ERROR ifs same condition + } else if a == 1 { + } + + // See #659 + if cfg!(feature = "feature1-659") { + 1 + } else if cfg!(feature = "feature2-659") { + 2 + } else { + 3 + }; + + let mut v = vec![1]; + if v.pop() == None { + // ok, functions + } else if v.pop() == None { + } + + if v.len() == 42 { + // ok, functions + } else if v.len() == 42 { + } +} + +fn main() {} diff --git a/tests/ui/ifs_same_cond.stderr b/tests/ui/ifs_same_cond.stderr new file mode 100644 index 000000000000..0b0dd24194ed --- /dev/null +++ b/tests/ui/ifs_same_cond.stderr @@ -0,0 +1,39 @@ +error: this `if` has the same condition as a previous if + --> $DIR/ifs_same_cond.rs:9:15 + | +LL | } else if b { + | ^ + | + = note: `-D clippy::ifs-same-cond` implied by `-D warnings` +note: same as this + --> $DIR/ifs_same_cond.rs:8:8 + | +LL | if b { + | ^ + +error: this `if` has the same condition as a previous if + --> $DIR/ifs_same_cond.rs:14:15 + | +LL | } else if a == 1 { + | ^^^^^^ + | +note: same as this + --> $DIR/ifs_same_cond.rs:13:8 + | +LL | if a == 1 { + | ^^^^^^ + +error: this `if` has the same condition as a previous if + --> $DIR/ifs_same_cond.rs:20:15 + | +LL | } else if 2 * a == 1 { + | ^^^^^^^^^^ + | +note: same as this + --> $DIR/ifs_same_cond.rs:18:8 + | +LL | if 2 * a == 1 { + | ^^^^^^^^^^ + +error: aborting due to 3 previous errors +