]> git.lizzy.rs Git - rust.git/blob - tests/ui/formatting.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / formatting.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![warn(clippy::all)]
11 #![allow(unused_variables)]
12 #![allow(unused_assignments)]
13 #![allow(clippy::if_same_then_else)]
14 #![allow(clippy::deref_addrof)]
15
16 fn foo() -> bool { true }
17
18 fn main() {
19     // weird `else` formatting:
20     if foo() {
21     } {
22     }
23
24     if foo() {
25     } if foo() {
26     }
27
28     let _ = { // if as the last expression
29         let _ = 0;
30
31         if foo() {
32         } if foo() {
33         }
34         else {
35         }
36     };
37
38     let _ = { // if in the middle of a block
39         if foo() {
40         } if foo() {
41         }
42         else {
43         }
44
45         let _ = 0;
46     };
47
48     if foo() {
49     } else
50     {
51     }
52
53     if foo() {
54     }
55     else
56     {
57     }
58
59     if foo() {
60     } else
61     if foo() { // the span of the above error should continue here
62     }
63
64     if foo() {
65     }
66     else
67     if foo() { // the span of the above error should continue here
68     }
69
70     // those are ok:
71     if foo() {
72     }
73     {
74     }
75
76     if foo() {
77     } else {
78     }
79
80     if foo() {
81     }
82     else {
83     }
84
85     if foo() {
86     }
87     if foo() {
88     }
89
90     if foo() {
91     } else if foo() {
92     }
93
94     if foo() {
95     }
96     else if foo() {
97     }
98
99     if foo() {
100     }
101     else if
102     foo() {}
103
104     // weird op_eq formatting:
105     let mut a = 42;
106     a =- 35;
107     a =* &191;
108
109     let mut b = true;
110     b =! false;
111
112     // those are ok:
113     a = -35;
114     a = *&191;
115     b = !false;
116
117     // possible missing comma in an array
118     let _ = &[
119         -1, -2, -3 // <= no comma here
120         -4, -5, -6
121     ];
122     let _ = &[
123         -1, -2, -3 // <= no comma here
124         *4, -5, -6
125     ];
126
127     // those are ok:
128     let _ = &[
129         -1, -2, -3,
130         -4, -5, -6
131     ];
132     let _ = &[
133         -1, -2, -3,
134         -4, -5, -6,
135     ];
136     let _ = &[
137         1 + 2, 3 +
138         4, 5 + 6,
139     ];
140
141     // don't lint for bin op without unary equiv
142     // issue 3244
143     vec![
144         1
145         / 2,
146     ];
147     // issue 3396
148     vec![
149         true
150         | false,
151     ];
152 }