Skip to content

Commit

Permalink
Auto merge of rust-lang#3612 - phansch:copies_cleanup, r=flip1995
Browse files Browse the repository at this point in the history
UI test cleanup: Extract ifs_same_cond tests

cc rust-lang#2038
  • Loading branch information
bors committed Jan 2, 2019
2 parents 51c77c1 + 3b03537 commit 3de9a3d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 82 deletions.
44 changes: 0 additions & 44 deletions tests/ui/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 1 addition & 38 deletions tests/ui/copies.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 46 additions & 0 deletions tests/ui/ifs_same_cond.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 39 additions & 0 deletions tests/ui/ifs_same_cond.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3de9a3d

Please sign in to comment.