forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#3612 - phansch:copies_cleanup, r=flip1995
UI test cleanup: Extract ifs_same_cond tests cc rust-lang#2038
- Loading branch information
Showing
4 changed files
with
86 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|