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