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