]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/suspicious_else_formatting.rs
Auto merge of #84620 - Dylan-DPC:rollup-wkv97im, r=Dylan-DPC
[rust.git] / src / tools / clippy / tests / ui / suspicious_else_formatting.rs
1 #![warn(clippy::suspicious_else_formatting)]
2
3 fn foo() -> bool {
4     true
5 }
6
7 #[rustfmt::skip]
8 fn main() {
9     // weird `else` formatting:
10     if foo() {
11     } {
12     }
13
14     if foo() {
15     } if foo() {
16     }
17
18     let _ = { // if as the last expression
19         let _ = 0;
20
21         if foo() {
22         } if foo() {
23         }
24         else {
25         }
26     };
27
28     let _ = { // if in the middle of a block
29         if foo() {
30         } if foo() {
31         }
32         else {
33         }
34
35         let _ = 0;
36     };
37
38     if foo() {
39     } else
40     {
41     }
42
43     // This is fine, though weird. Allman style braces on the else.
44     if foo() {
45     }
46     else
47     {
48     }
49
50     if foo() {
51     } else
52     if foo() { // the span of the above error should continue here
53     }
54
55     if foo() {
56     }
57     else
58     if foo() { // the span of the above error should continue here
59     }
60
61     // those are ok:
62     if foo() {
63     }
64     {
65     }
66
67     if foo() {
68     } else {
69     }
70
71     if foo() {
72     }
73     else {
74     }
75
76     if foo() {
77     }
78     if foo() {
79     }
80
81     // Almost Allman style braces. Lint these.
82     if foo() {
83     }
84
85     else
86     {
87
88     }
89
90     if foo() {
91     }
92     else
93
94     {
95
96     }
97
98     // #3864 - Allman style braces
99     if foo()
100     {
101     }
102     else
103     {
104     }
105 }