]> git.lizzy.rs Git - rust.git/blob - tests/ui/formatting.rs
Merge branch 'master' into rustfmt_tests
[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 if` formatting:
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     if foo() { // the span of the above error should continue here
47     }
48
49     if foo() {
50     }
51     else
52     if foo() { // the span of the above error should continue here
53     }
54
55     // those are ok:
56     if foo() {
57     }
58     if foo() {
59     }
60
61     if foo() {
62     } else if foo() {
63     }
64
65     if foo() {
66     }
67     else if foo() {
68     }
69
70     if foo() {
71     }
72     else if
73     foo() {}
74
75     // weird op_eq formatting:
76     let mut a = 42;
77     a =- 35;
78     a =* &191;
79
80     let mut b = true;
81     b =! false;
82
83     // those are ok:
84     a = -35;
85     a = *&191;
86     b = !false;
87
88     // possible missing comma in an array
89     let _ = &[
90         -1, -2, -3 // <= no comma here
91         -4, -5, -6
92     ];
93     let _ = &[
94         -1, -2, -3 // <= no comma here
95         *4, -5, -6
96     ];
97
98     // those are ok:
99     let _ = &[
100         -1, -2, -3,
101         -4, -5, -6
102     ];
103     let _ = &[
104         -1, -2, -3,
105         -4, -5, -6,
106     ];
107     let _ = &[
108         1 + 2, 3 +
109         4, 5 + 6,
110     ];
111
112     // don't lint for bin op without unary equiv
113     // issue 3244
114     vec![
115         1
116         / 2,
117     ];
118     // issue 3396
119     vec![
120         true
121         | false,
122     ];
123 }