]> git.lizzy.rs Git - rust.git/blob - tests/ui/formatting.rs
Merge branch 'master' into add-lints-aseert-checks
[rust.git] / 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 { true }
8
9 fn main() {
10     // weird `else` formatting:
11     if foo() {
12     } {
13     }
14
15     if foo() {
16     } if foo() {
17     }
18
19     let _ = { // if as the last expression
20         let _ = 0;
21
22         if foo() {
23         } if foo() {
24         }
25         else {
26         }
27     };
28
29     let _ = { // if in the middle of a block
30         if foo() {
31         } if foo() {
32         }
33         else {
34         }
35
36         let _ = 0;
37     };
38
39     if foo() {
40     } else
41     {
42     }
43
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     if foo() {
82     } else if foo() {
83     }
84
85     if foo() {
86     }
87     else if foo() {
88     }
89
90     if foo() {
91     }
92     else if
93     foo() {}
94
95     // weird op_eq formatting:
96     let mut a = 42;
97     a =- 35;
98     a =* &191;
99
100     let mut b = true;
101     b =! false;
102
103     // those are ok:
104     a = -35;
105     a = *&191;
106     b = !false;
107
108     // possible missing comma in an array
109     let _ = &[
110         -1, -2, -3 // <= no comma here
111         -4, -5, -6
112     ];
113     let _ = &[
114         -1, -2, -3 // <= no comma here
115         *4, -5, -6
116     ];
117
118     // those are ok:
119     let _ = &[
120         -1, -2, -3,
121         -4, -5, -6
122     ];
123     let _ = &[
124         -1, -2, -3,
125         -4, -5, -6,
126     ];
127     let _ = &[
128         1 + 2, 3 +
129         4, 5 + 6,
130     ];
131
132     // don't lint for bin op without unary equiv
133     // issue 3244
134     vec![
135         1
136         / 2,
137     ];
138     // issue 3396
139     vec![
140         true
141         | false,
142     ];
143 }