]> git.lizzy.rs Git - rust.git/blob - tests/target/expr-block.rs
Merge pull request #1782 from topecongiro/rfc/combining-match-arm
[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 => baz!(
177             function,
178             like,
179             macro_as,
180             expression,
181             which,
182             is,
183             loooooooooooooooong
184         ),
185         Some(p) => baz!(one_item_macro_as_expression_which_is_also_loooooooooooooooong),
186     };
187 }
188
189 fn issue_1450() {
190     if selfstate
191         .compare_exchandsfasdsdfgsdgsdfgsdfgsdfgsdfgsdfgfsfdsage_weak(
192             STATE_PARKED,
193             STATE_UNPARKED,
194             Release,
195             Relaxed,
196             Release,
197             Relaxed,
198         )
199         .is_ok()
200     {
201         return;
202     }
203 }
204
205 fn foo() {
206     if real_total <= limit && !pre_line_comments &&
207         !items.into_iter().any(|item| item.as_ref().is_multiline())
208     {
209         DefinitiveListTactic::Horizontal
210     }
211 }
212
213 fn combine_block() {
214     foo(Bar {
215         x: value,
216         y: value2,
217     });
218
219     foo((Bar {
220         x: value,
221         y: value2,
222     },));
223
224     foo((
225         1,
226         2,
227         3,
228         Bar {
229             x: value,
230             y: value2,
231         },
232     ));
233
234     foo((1, 2, 3, |x| {
235         let y = x + 1;
236         let z = y + 1;
237         z
238     }));
239
240     let opt = Some(Struct(
241         long_argument_one,
242         long_argument_two,
243         long_argggggggg,
244     ));
245
246     do_thing(|param| {
247         action();
248         foo(param)
249     });
250
251     do_thing(x, |param| {
252         action();
253         foo(param)
254     });
255
256     do_thing(
257         x,
258         (1, 2, 3, |param| {
259             action();
260             foo(param)
261         }),
262     );
263
264     Ok(some_function(
265         lllllllllong_argument_one,
266         lllllllllong_argument_two,
267         lllllllllllllllllllllllllllllong_argument_three,
268     ));
269
270     foo(
271         thing,
272         bar(
273             param2,
274             pparam1param1param1param1param1param1param1param1param1param1aram1,
275             param3,
276         ),
277     );
278
279     foo.map_or(|| {
280         Ok(SomeStruct {
281             f1: 0,
282             f2: 0,
283             f3: 0,
284         })
285     });
286
287     match opt {
288         Some(x) => somefunc(anotherfunc(
289             long_argument_one,
290             long_argument_two,
291             long_argument_three,
292         )),
293         Some(x) => |x| {
294             let y = x + 1;
295             let z = y + 1;
296             z
297         },
298         Some(x) => (1, 2, |x| {
299             let y = x + 1;
300             let z = y + 1;
301             z
302         }),
303         Some(x) => SomeStruct {
304             f1: long_argument_one,
305             f2: long_argument_two,
306             f3: long_argument_three,
307         },
308         None => Ok(SomeStruct {
309             f1: long_argument_one,
310             f2: long_argument_two,
311             f3: long_argument_three,
312         }),
313     };
314
315     match x {
316         y => func(
317             xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
318         ),
319         _ => func(
320             x,
321             yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
322             zzz,
323         ),
324     }
325 }