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