]> git.lizzy.rs Git - rust.git/blob - tests/target/expr-block.rs
Merge pull request #1510 from fintelia/better-filelines
[rust.git] / tests / target / expr-block.rs
1 // rustfmt-array_layout: Block
2 // rustfmt-fn_call_style: Block
3 // rustfmt-control_style: Rfc
4 // Test expressions with block formatting.
5
6 fn arrays() {
7     [];
8     let empty = [];
9
10     let foo = [a_long_name, a_very_lng_name, a_long_name];
11
12     let foo = [
13         a_long_name,
14         a_very_lng_name,
15         a_long_name,
16         a_very_lng_name,
17         a_long_name,
18         a_very_lng_name,
19         a_long_name,
20         a_very_lng_name,
21     ];
22
23     vec![
24         a_long_name,
25         a_very_lng_name,
26         a_long_name,
27         a_very_lng_name,
28         a_long_name,
29         a_very_lng_name,
30         a_very_lng_name,
31     ];
32
33     [
34         a_long_name,
35         a_very_lng_name,
36         a_long_name,
37         a_very_lng_name,
38         a_long_name,
39         a_very_lng_name,
40         a_very_lng_name,
41     ]
42 }
43
44 fn arrays() {
45     let x = [
46         0,
47         1,
48         2,
49         3,
50         4,
51         5,
52         6,
53         7,
54         8,
55         9,
56         0,
57         1,
58         2,
59         3,
60         4,
61         5,
62         6,
63         7,
64         8,
65         9,
66         0,
67         7,
68         8,
69         9,
70         0,
71         1,
72         2,
73         3,
74         4,
75         5,
76         6,
77         7,
78         8,
79         9,
80         0,
81     ];
82
83     let y = [
84         /* comment */
85         1,
86         2, /* post comment */
87         3,
88     ];
89
90     let xy = [
91         strukt {
92             test123: value_one_two_three_four,
93             turbo: coolio(),
94         },
95         /* comment  */
96         1,
97     ];
98
99     let a = WeightedChoice::new(
100         &mut [
101             Weighted { weight: x, item: 0 },
102             Weighted { weight: 1, item: 1 },
103             Weighted { weight: x, item: 2 },
104             Weighted { weight: 1, item: 3 },
105         ]
106     );
107
108     let z = [
109         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
110         yyyyyyyyyyyyyyyyyyyyyyyyyyy,
111         zzzzzzzzzzzzzzzzz,
112         q,
113     ];
114
115     [1 + 3, 4, 5, 6, 7, 7, fncall::<Vec<_>>(3 - 1)]
116 }
117
118 fn function_calls() {
119     let items = itemize_list(
120         context.codemap,
121         args.iter(),
122         ")",
123         |item| item.span.lo,
124         |item| item.span.hi,
125         |item| {
126             item.rewrite(
127                 context,
128                 Shape {
129                     width: remaining_width,
130                     ..nested_shape
131                 },
132             )
133         },
134         span.lo,
135         span.hi,
136     );
137
138     itemize_list(
139         context.codemap,
140         args.iter(),
141         ")",
142         |item| item.span.lo,
143         |item| item.span.hi,
144         |item| {
145             item.rewrite(
146                 context,
147                 Shape {
148                     width: remaining_width,
149                     ..nested_shape
150                 },
151             )
152         },
153         span.lo,
154         span.hi,
155     )
156 }
157
158 fn macros() {
159     baz!(
160         do_not,
161         add,
162         trailing,
163         commas,
164         inside,
165         of,
166         function,
167         like,
168         macros,
169         even,
170         if_they,
171         are,
172         long
173     );
174
175     baz!(one_item_macro_which_is_also_loooooooooooooooooooooooooooooooooooooooooooooooong);
176
177     let _ = match option {
178         None => {
179             baz!(
180                 function,
181                 like,
182                 macro_as,
183                 expression,
184                 which,
185                 is,
186                 loooooooooooooooong
187             )
188         }
189         Some(p) => baz!(one_item_macro_as_expression_which_is_also_loooooooooooooooong),
190     };
191 }
192
193 fn issue_1450() {
194     if selfstate
195         .compare_exchandsfasdsdfgsdgsdfgsdfgsdfgsdfgsdfgfsfdsage_weak(
196             STATE_PARKED,
197             STATE_UNPARKED,
198             Release,
199             Relaxed,
200             Release,
201             Relaxed,
202         )
203         .is_ok()
204     {
205         return;
206     }
207 }
208
209 fn foo() {
210     if real_total <= limit && !pre_line_comments &&
211         !items.into_iter().any(|item| item.as_ref().is_multiline())
212     {
213         DefinitiveListTactic::Horizontal
214     }
215 }