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