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