mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
UI test cleanup: Extract ifs_same_cond tests
This commit is contained in:
parent
85ba5f0f17
commit
3b035373b2
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
46
tests/ui/ifs_same_cond.rs
Normal file
46
tests/ui/ifs_same_cond.rs
Normal file
@ -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() {}
|
39
tests/ui/ifs_same_cond.stderr
Normal file
39
tests/ui/ifs_same_cond.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user