2019-01-13 10:44:45 +00:00
|
|
|
// run-rustfix
|
2019-02-23 01:19:50 +00:00
|
|
|
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
|
2019-01-13 10:44:45 +00:00
|
|
|
|
2018-12-08 17:56:59 +00:00
|
|
|
#[rustfmt::skip]
|
2018-07-28 15:34:52 +00:00
|
|
|
#[warn(clippy::collapsible_if)]
|
2015-05-29 14:07:34 +00:00
|
|
|
fn main() {
|
|
|
|
let x = "hello";
|
|
|
|
let y = "world";
|
2016-06-07 16:32:26 +00:00
|
|
|
if x == "hello" {
|
2015-05-29 14:07:34 +00:00
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 16:32:26 +00:00
|
|
|
if x == "hello" || x == "world" {
|
2015-05-29 14:07:34 +00:00
|
|
|
if y == "world" || y == "hello" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 19:26:26 +00:00
|
|
|
if x == "hello" && x == "world" {
|
|
|
|
if y == "world" || y == "hello" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" || x == "world" {
|
|
|
|
if y == "world" && y == "hello" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" && x == "world" {
|
|
|
|
if y == "world" && y == "hello" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if 42 == 1337 {
|
|
|
|
if 'a' != 'A' {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 02:13:14 +00:00
|
|
|
// Collapse `else { if .. }` to `else if ..`
|
2016-01-13 17:32:55 +00:00
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
2016-06-21 21:53:45 +00:00
|
|
|
} else {
|
2016-01-13 17:32:55 +00:00
|
|
|
if y == "world" {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
2016-06-21 21:53:45 +00:00
|
|
|
} else {
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
2016-01-13 17:32:55 +00:00
|
|
|
if y == "world" {
|
|
|
|
println!("world")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 21:53:45 +00:00
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
println!("world")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
println!("world")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
if x == "hello" {
|
|
|
|
println!("world")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
println!("world")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 14:07:34 +00:00
|
|
|
// Works because any if with an else statement cannot be collapsed.
|
|
|
|
if x == "hello" {
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
println!("Not Hello world");
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
} else {
|
|
|
|
println!("Hello something else");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-11 18:22:20 +00:00
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
if y == "world" {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
2016-07-01 15:41:57 +00:00
|
|
|
|
|
|
|
if true {
|
|
|
|
} else {
|
|
|
|
assert!(true); // assert! is just an `if`
|
|
|
|
}
|
2018-10-16 20:20:27 +00:00
|
|
|
|
|
|
|
|
2018-11-22 03:40:09 +00:00
|
|
|
// The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
|
2018-10-16 20:20:27 +00:00
|
|
|
if x == "hello" {// Not collapsible
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" { // Not collapsible
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
// Not collapsible
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
if y == "world" { // Collapsible
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
// Not collapsible
|
|
|
|
if y == "world" {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
// Not collapsible
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
2018-10-18 16:57:16 +00:00
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
/* Not collapsible */
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" { /* Not collapsible */
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
2015-05-29 14:07:34 +00:00
|
|
|
}
|