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