]> git.lizzy.rs Git - rust.git/blob - tests/ui/collapsible_if.rs
Auto merge of #3646 - matthiaskrgr:travis, r=phansch
[rust.git] / tests / ui / collapsible_if.rs
1 #[rustfmt::skip]
2 #[warn(clippy::collapsible_if)]
3 fn main() {
4     let x = "hello";
5     let y = "world";
6     if x == "hello" {
7         if y == "world" {
8             println!("Hello world!");
9         }
10     }
11
12     if x == "hello" || x == "world" {
13         if y == "world" || y == "hello" {
14             println!("Hello world!");
15         }
16     }
17
18     if x == "hello" && x == "world" {
19         if y == "world" || y == "hello" {
20             println!("Hello world!");
21         }
22     }
23
24     if x == "hello" || x == "world" {
25         if y == "world" && y == "hello" {
26             println!("Hello world!");
27         }
28     }
29
30     if x == "hello" && x == "world" {
31         if y == "world" && y == "hello" {
32             println!("Hello world!");
33         }
34     }
35
36     if 42 == 1337 {
37         if 'a' != 'A' {
38             println!("world!")
39         }
40     }
41
42     // Collapse `else { if .. }` to `else if ..`
43     if x == "hello" {
44         print!("Hello ");
45     } else {
46         if y == "world" {
47             println!("world!")
48         }
49     }
50
51     if x == "hello" {
52         print!("Hello ");
53     } else {
54         if let Some(42) = Some(42) {
55             println!("world!")
56         }
57     }
58
59     if x == "hello" {
60         print!("Hello ");
61     } else {
62         if y == "world" {
63             println!("world")
64         }
65         else {
66             println!("!")
67         }
68     }
69
70     if x == "hello" {
71         print!("Hello ");
72     } else {
73         if let Some(42) = Some(42) {
74             println!("world")
75         }
76         else {
77             println!("!")
78         }
79     }
80
81     if let Some(42) = Some(42) {
82         print!("Hello ");
83     } else {
84         if let Some(42) = Some(42) {
85             println!("world")
86         }
87         else {
88             println!("!")
89         }
90     }
91
92     if let Some(42) = Some(42) {
93         print!("Hello ");
94     } else {
95         if x == "hello" {
96             println!("world")
97         }
98         else {
99             println!("!")
100         }
101     }
102
103     if let Some(42) = Some(42) {
104         print!("Hello ");
105     } else {
106         if let Some(42) = Some(42) {
107             println!("world")
108         }
109         else {
110             println!("!")
111         }
112     }
113
114     // Works because any if with an else statement cannot be collapsed.
115     if x == "hello" {
116         if y == "world" {
117             println!("Hello world!");
118         }
119     } else {
120         println!("Not Hello world");
121     }
122
123     if x == "hello" {
124         if y == "world" {
125             println!("Hello world!");
126         } else {
127             println!("Hello something else");
128         }
129     }
130
131     if x == "hello" {
132         print!("Hello ");
133         if y == "world" {
134             println!("world!")
135         }
136     }
137
138     if true {
139     } else {
140         assert!(true); // assert! is just an `if`
141     }
142
143
144     // The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
145     if x == "hello" {// Not collapsible
146         if y == "world" {
147             println!("Hello world!");
148         }
149     }
150
151     if x == "hello" { // Not collapsible
152         if y == "world" {
153             println!("Hello world!");
154         }
155     }
156
157     if x == "hello" {
158         // Not collapsible
159         if y == "world" {
160             println!("Hello world!");
161         }
162     }
163
164     if x == "hello" {
165         if y == "world" { // Collapsible
166             println!("Hello world!");
167         }
168     }
169
170     if x == "hello" {
171         print!("Hello ");
172     } else {
173         // Not collapsible
174         if y == "world" {
175             println!("world!")
176         }
177     }
178
179     if x == "hello" {
180         print!("Hello ");
181     } else {
182         // Not collapsible
183         if let Some(42) = Some(42) {
184             println!("world!")
185         }
186     }
187
188     if x == "hello" {
189         /* Not collapsible */
190         if y == "world" {
191             println!("Hello world!");
192         }
193     }
194
195     if x == "hello" { /* Not collapsible */
196         if y == "world" {
197             println!("Hello world!");
198         }
199     }
200 }