rust/tests/compile-fail/collapsible_if.rs
Matthew Hall 7e16822925 Add lint for ifs that could be collapsed
"Collapsible" ifs are ones which contain only a then block, and the then
block consists of an if that only has a then block.
2015-05-29 15:41:25 +01:00

37 lines
837 B
Rust

#![feature(plugin)]
#![plugin(clippy)]
#[deny(collapsible_if)]
fn main() {
let x = "hello";
let y = "world";
if x == "hello" { //~ERROR This if statement can be collapsed
if y == "world" {
println!("Hello world!");
}
}
if x == "hello" || x == "world" { //~ERROR This if statement can be collapsed
if y == "world" || y == "hello" {
println!("Hello world!");
}
}
// 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");
}
}
}