]> git.lizzy.rs Git - rust.git/blob - tests/ui/formatting.rs
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 {
17     true
18 }
19
20 fn main() {
21     // weird `else if` formatting:
22     if foo() {}
23     if foo() {}
24
25     let _ = {
26         // if as the last expression
27         let _ = 0;
28
29         if foo() {}
30         if foo() {
31         } else {
32         }
33     };
34
35     let _ = {
36         // if in the middle of a block
37         if foo() {}
38         if foo() {
39         } else {
40         }
41
42         let _ = 0;
43     };
44
45     if foo() {
46     } else if foo() {
47         // the span of the above error should continue here
48     }
49
50     if foo() {
51     } else if foo() {
52         // the span of the above error should continue here
53     }
54
55     // those are ok:
56     if foo() {}
57     if foo() {}
58
59     if foo() {
60     } else if foo() {
61     }
62
63     if foo() {
64     } else if foo() {
65     }
66
67     if foo() {
68     } else if foo() {
69     }
70
71     // weird op_eq formatting:
72     let mut a = 42;
73     a = -35;
74     a = *&191;
75
76     let mut b = true;
77     b = !false;
78
79     // those are ok:
80     a = -35;
81     a = *&191;
82     b = !false;
83
84     // possible missing comma in an array
85     let _ = &[
86         -1,
87         -2,
88         -3 // <= no comma here
89         -4,
90         -5,
91         -6,
92     ];
93     let _ = &[
94         -1,
95         -2,
96         -3 // <= no comma here
97         *4,
98         -5,
99         -6,
100     ];
101
102     // those are ok:
103     let _ = &[-1, -2, -3, -4, -5, -6];
104     let _ = &[-1, -2, -3, -4, -5, -6];
105     let _ = &[1 + 2, 3 + 4, 5 + 6];
106
107     // don't lint for bin op without unary equiv
108     // issue 3244
109     vec![1 / 2];
110     // issue 3396
111     vec![true | false];
112 }