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