rust-clippy/tests/ui/collapsible_else_if.rs

92 lines
1.7 KiB
Rust
Raw Normal View History

2020-01-07 06:06:23 +00:00
// run-rustfix
2021-10-04 06:33:40 +00:00
#![allow(clippy::assertions_on_constants, clippy::equatable_if_let)]
2020-01-07 06:06:23 +00:00
#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
#[warn(clippy::collapsible_else_if)]
2020-01-07 06:06:23 +00:00
fn main() {
let x = "hello";
let y = "world";
// Collapse `else { if .. }` to `else if ..`
if x == "hello" {
print!("Hello ");
} else {
if y == "world" {
println!("world!")
}
}
if x == "hello" {
print!("Hello ");
} else {
if let Some(42) = Some(42) {
println!("world!")
}
}
if x == "hello" {
print!("Hello ");
} else {
if y == "world" {
println!("world")
}
else {
println!("!")
}
}
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!("!")
}
}
if x == "hello" {
print!("Hello ");
} else {
#[cfg(not(roflol))]
if y == "world" {
println!("world!")
}
}
2020-01-07 06:06:23 +00:00
}