]> git.lizzy.rs Git - rust.git/blob - tests/target/expr-block.rs
Update tests
[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(&mut [
100         Weighted { weight: x, item: 0 },
101         Weighted { weight: 1, item: 1 },
102         Weighted { weight: x, item: 2 },
103         Weighted { weight: 1, item: 3 },
104     ]);
105
106     let z = [
107         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
108         yyyyyyyyyyyyyyyyyyyyyyyyyyy,
109         zzzzzzzzzzzzzzzzz,
110         q,
111     ];
112
113     [1 + 3, 4, 5, 6, 7, 7, fncall::<Vec<_>>(3 - 1)]
114 }
115
116 fn function_calls() {
117     let items = itemize_list(
118         context.codemap,
119         args.iter(),
120         ")",
121         |item| item.span.lo,
122         |item| item.span.hi,
123         |item| {
124             item.rewrite(
125                 context,
126                 Shape {
127                     width: remaining_width,
128                     ..nested_shape
129                 },
130             )
131         },
132         span.lo,
133         span.hi,
134     );
135
136     itemize_list(
137         context.codemap,
138         args.iter(),
139         ")",
140         |item| item.span.lo,
141         |item| item.span.hi,
142         |item| {
143             item.rewrite(
144                 context,
145                 Shape {
146                     width: remaining_width,
147                     ..nested_shape
148                 },
149             )
150         },
151         span.lo,
152         span.hi,
153     )
154 }
155
156 fn macros() {
157     baz!(
158         do_not,
159         add,
160         trailing,
161         commas,
162         inside,
163         of,
164         function,
165         like,
166         macros,
167         even,
168         if_they,
169         are,
170         long
171     );
172
173     baz!(one_item_macro_which_is_also_loooooooooooooooooooooooooooooooooooooooooooooooong);
174
175     let _ = match option {
176         None => {
177             baz!(
178                 function,
179                 like,
180                 macro_as,
181                 expression,
182                 which,
183                 is,
184                 loooooooooooooooong
185             )
186         }
187         Some(p) => baz!(one_item_macro_as_expression_which_is_also_loooooooooooooooong),
188     };
189 }
190
191 fn issue_1450() {
192     if selfstate
193         .compare_exchandsfasdsdfgsdgsdfgsdfgsdfgsdfgsdfgfsfdsage_weak(
194             STATE_PARKED,
195             STATE_UNPARKED,
196             Release,
197             Relaxed,
198             Release,
199             Relaxed,
200         )
201         .is_ok()
202     {
203         return;
204     }
205 }
206
207 fn foo() {
208     if real_total <= limit && !pre_line_comments &&
209         !items.into_iter().any(|item| item.as_ref().is_multiline())
210     {
211         DefinitiveListTactic::Horizontal
212     }
213 }
214
215 fn combine_block() {
216     foo(Bar {
217         x: value,
218         y: value2,
219     });
220
221     foo((Bar {
222         x: value,
223         y: value2,
224     },));
225
226     foo((
227         1,
228         2,
229         3,
230         Bar {
231             x: value,
232             y: value2,
233         },
234     ));
235
236     foo((1, 2, 3, |x| {
237         let y = x + 1;
238         let z = y + 1;
239         z
240     }));
241
242     let opt = Some(Struct(
243         long_argument_one,
244         long_argument_two,
245         long_argggggggg,
246     ));
247
248     do_thing(|param| {
249         action();
250         foo(param)
251     });
252
253     do_thing(x, |param| {
254         action();
255         foo(param)
256     });
257
258     do_thing(
259         x,
260         (1, 2, 3, |param| {
261             action();
262             foo(param)
263         }),
264     );
265
266     Ok(some_function(
267         lllllllllong_argument_one,
268         lllllllllong_argument_two,
269         lllllllllllllllllllllllllllllong_argument_three,
270     ));
271
272     foo(
273         thing,
274         bar(
275             param2,
276             pparam1param1param1param1param1param1param1param1param1param1aram1,
277             param3,
278         ),
279     );
280
281     foo.map_or(|| {
282         Ok(SomeStruct {
283             f1: 0,
284             f2: 0,
285             f3: 0,
286         })
287     });
288
289     match opt {
290         Some(x) => somefunc(anotherfunc(
291             long_argument_one,
292             long_argument_two,
293             long_argument_three,
294         )),
295         Some(x) => |x| {
296             let y = x + 1;
297             let z = y + 1;
298             z
299         },
300         Some(x) => (1, 2, |x| {
301             let y = x + 1;
302             let z = y + 1;
303             z
304         }),
305         Some(x) => SomeStruct {
306             f1: long_argument_one,
307             f2: long_argument_two,
308             f3: long_argument_three,
309         },
310         None => Ok(SomeStruct {
311             f1: long_argument_one,
312             f2: long_argument_two,
313             f3: long_argument_three,
314         }),
315     };
316
317     match x {
318         y => func(
319             xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
320         ),
321         _ => {
322             func(
323                 x,
324                 yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
325                 zzz,
326             )
327         }
328     }
329 }