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