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