]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/collapsible_if.rs
280744b5b45c2d98919262cdb5f4b78d78cd6604
[rust.git] / tests / compile-fail / collapsible_if.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #[deny(collapsible_if)]
5 fn main() {
6     let x = "hello";
7     let y = "world";
8     if x == "hello" { //~ERROR This if statement can be collapsed
9         if y == "world" {
10             println!("Hello world!");
11         }
12     }
13
14     if x == "hello" || x == "world" { //~ERROR This if statement can be collapsed
15         if y == "world" || y == "hello" {
16             println!("Hello world!");
17         }
18     }
19
20     // Works because any if with an else statement cannot be collapsed.
21     if x == "hello" {
22         if y == "world" {
23             println!("Hello world!");
24         }
25     } else {
26         println!("Not Hello world");
27     }
28
29     if x == "hello" {
30         if y == "world" {
31             println!("Hello world!");
32         } else {
33             println!("Hello something else");
34         }
35     }
36
37     if x == "hello" {
38         print!("Hello ");
39         if y == "world" {
40             println!("world!")
41         }
42     }
43 }