]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/collapsible_else_if.rs
Rollup merge of #100462 - zohnannor:master, r=thomcc
[rust.git] / src / tools / clippy / tests / ui / collapsible_else_if.rs
1 // run-rustfix
2 #![allow(clippy::assertions_on_constants, clippy::equatable_if_let)]
3
4 #[rustfmt::skip]
5 #[warn(clippy::collapsible_if)]
6 #[warn(clippy::collapsible_else_if)]
7
8 fn main() {
9     let x = "hello";
10     let y = "world";
11     // Collapse `else { if .. }` to `else if ..`
12     if x == "hello" {
13         print!("Hello ");
14     } else {
15         if y == "world" {
16             println!("world!")
17         }
18     }
19
20     if x == "hello" {
21         print!("Hello ");
22     } else {
23         if let Some(42) = Some(42) {
24             println!("world!")
25         }
26     }
27
28     if x == "hello" {
29         print!("Hello ");
30     } else {
31         if y == "world" {
32             println!("world")
33         }
34         else {
35             println!("!")
36         }
37     }
38
39     if x == "hello" {
40         print!("Hello ");
41     } else {
42         if let Some(42) = Some(42) {
43             println!("world")
44         }
45         else {
46             println!("!")
47         }
48     }
49
50     if let Some(42) = Some(42) {
51         print!("Hello ");
52     } else {
53         if let Some(42) = Some(42) {
54             println!("world")
55         }
56         else {
57             println!("!")
58         }
59     }
60
61     if let Some(42) = Some(42) {
62         print!("Hello ");
63     } else {
64         if x == "hello" {
65             println!("world")
66         }
67         else {
68             println!("!")
69         }
70     }
71
72     if let Some(42) = Some(42) {
73         print!("Hello ");
74     } else {
75         if let Some(42) = Some(42) {
76             println!("world")
77         }
78         else {
79             println!("!")
80         }
81     }
82
83     if x == "hello" {
84         print!("Hello ");
85     } else {
86         #[cfg(not(roflol))]
87         if y == "world" {
88             println!("world!")
89         }
90     }
91 }
92
93 #[rustfmt::skip]
94 #[allow(dead_code)]
95 fn issue_7318() {
96     if true { println!("I've been resolved!")
97     }else{
98         if false {}
99     }
100 }