rust/tests/ui/collapsible_else_if.fixed

67 lines
1.3 KiB
Rust
Raw Normal View History

2020-01-07 00:06:23 -06:00
// run-rustfix
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
fn main() {
let x = "hello";
let y = "world";
// Collapse `else { if .. }` to `else if ..`
if x == "hello" {
print!("Hello ");
} else if y == "world" {
2020-02-04 09:13:06 -06:00
println!("world!")
}
2020-01-07 00:06:23 -06:00
if x == "hello" {
print!("Hello ");
} else if let Some(42) = Some(42) {
2020-02-04 09:13:06 -06:00
println!("world!")
}
2020-01-07 00:06:23 -06:00
if x == "hello" {
print!("Hello ");
} else if y == "world" {
2020-02-04 09:13:06 -06:00
println!("world")
}
else {
println!("!")
}
2020-01-07 00:06:23 -06:00
if x == "hello" {
print!("Hello ");
} else if let Some(42) = Some(42) {
2020-02-04 09:13:06 -06:00
println!("world")
}
else {
println!("!")
}
2020-01-07 00:06:23 -06:00
if let Some(42) = Some(42) {
print!("Hello ");
} else if let Some(42) = Some(42) {
2020-02-04 09:13:06 -06:00
println!("world")
}
else {
println!("!")
}
2020-01-07 00:06:23 -06:00
if let Some(42) = Some(42) {
print!("Hello ");
} else if x == "hello" {
2020-02-04 09:13:06 -06:00
println!("world")
}
else {
println!("!")
}
2020-01-07 00:06:23 -06:00
if let Some(42) = Some(42) {
print!("Hello ");
} else if let Some(42) = Some(42) {
2020-02-04 09:13:06 -06:00
println!("world")
}
else {
println!("!")
}
2020-01-07 00:06:23 -06:00
}