]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/formatting.rs
Rollup merge of #75190 - GuillaumeGomez:cleanup-e0746, r=Dylan-DPC
[rust.git] / src / tools / clippy / tests / ui / formatting.rs
1 #![warn(clippy::all)]
2 #![allow(unused_variables)]
3 #![allow(unused_assignments)]
4 #![allow(clippy::if_same_then_else)]
5 #![allow(clippy::deref_addrof)]
6
7 fn foo() -> bool {
8     true
9 }
10
11 #[rustfmt::skip]
12 fn main() {
13     // weird `else` formatting:
14     if foo() {
15     } {
16     }
17
18     if foo() {
19     } if foo() {
20     }
21
22     let _ = { // if as the last expression
23         let _ = 0;
24
25         if foo() {
26         } if foo() {
27         }
28         else {
29         }
30     };
31
32     let _ = { // if in the middle of a block
33         if foo() {
34         } if foo() {
35         }
36         else {
37         }
38
39         let _ = 0;
40     };
41
42     if foo() {
43     } else
44     {
45     }
46
47     if foo() {
48     }
49     else
50     {
51     }
52
53     if foo() {
54     } else
55     if foo() { // the span of the above error should continue here
56     }
57
58     if foo() {
59     }
60     else
61     if foo() { // the span of the above error should continue here
62     }
63
64     // those are ok:
65     if foo() {
66     }
67     {
68     }
69
70     if foo() {
71     } else {
72     }
73
74     if foo() {
75     }
76     else {
77     }
78
79     if foo() {
80     }
81     if foo() {
82     }
83
84     if foo() {
85     } else if foo() {
86     }
87
88     if foo() {
89     }
90     else if foo() {
91     }
92
93     if foo() {
94     }
95     else if
96     foo() {}
97
98     // weird op_eq formatting:
99     let mut a = 42;
100     a =- 35;
101     a =* &191;
102
103     let mut b = true;
104     b =! false;
105
106     // those are ok:
107     a = -35;
108     a = *&191;
109     b = !false;
110
111     // possible missing comma in an array
112     let _ = &[
113         -1, -2, -3 // <= no comma here
114         -4, -5, -6
115     ];
116     let _ = &[
117         -1, -2, -3 // <= no comma here
118         *4, -5, -6
119     ];
120
121     // those are ok:
122     let _ = &[
123         -1, -2, -3,
124         -4, -5, -6
125     ];
126     let _ = &[
127         -1, -2, -3,
128         -4, -5, -6,
129     ];
130     let _ = &[
131         1 + 2, 3 +
132         4, 5 + 6,
133     ];
134
135     // don't lint for bin op without unary equiv
136     // issue 3244
137     vec![
138         1
139         / 2,
140     ];
141     // issue 3396
142     vec![
143         true
144         | false,
145     ];
146
147     // don't lint if the indentation suggests not to
148     let _ = &[
149         1 + 2, 3 
150                 - 4, 5
151     ];
152     // lint if it doesn't
153     let _ = &[
154         -1
155         -4,
156     ];
157 }