]> git.proxmox.com Git - rustc.git/blame - src/tools/rustfmt/tests/target/expr-block.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / rustfmt / tests / target / expr-block.rs
CommitLineData
f20569fa
XL
1// Test expressions with block formatting.
2
3fn 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
41fn 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
74fn 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
114fn 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
135fn issue_1450() {
136 if selfstate
137 .compare_exchandsfasdsdfgsdgsdfgsdfgsdfgsdfgsdfgfsfdsage_weak(
138 STATE_PARKED,
139 STATE_UNPARKED,
140 Release,
141 Relaxed,
142 Release,
143 Relaxed,
144 )
145 .is_ok()
146 {
147 return;
148 }
149}
150
151fn foo() {
152 if real_total <= limit
153 && !pre_line_comments
154 && !items.into_iter().any(|item| item.as_ref().is_multiline())
155 {
156 DefinitiveListTactic::Horizontal
157 }
158}
159
160fn combine_block() {
161 foo(Bar {
162 x: value,
163 y: value2,
164 });
165
166 foo((Bar {
167 x: value,
168 y: value2,
169 },));
170
171 foo((
172 1,
173 2,
174 3,
175 Bar {
176 x: value,
177 y: value2,
178 },
179 ));
180
181 foo((1, 2, 3, |x| {
182 let y = x + 1;
183 let z = y + 1;
184 z
185 }));
186
187 let opt = Some(Struct(
188 long_argument_one,
189 long_argument_two,
190 long_argggggggg,
191 ));
192
193 do_thing(|param| {
194 action();
195 foo(param)
196 });
197
198 do_thing(x, |param| {
199 action();
200 foo(param)
201 });
202
203 do_thing(
204 x,
205 (1, 2, 3, |param| {
206 action();
207 foo(param)
208 }),
209 );
210
211 Ok(some_function(
212 lllllllllong_argument_one,
213 lllllllllong_argument_two,
214 lllllllllllllllllllllllllllllong_argument_three,
215 ));
216
217 foo(
218 thing,
219 bar(
220 param2,
221 pparam1param1param1param1param1param1param1param1param1param1aram1,
222 param3,
223 ),
224 );
225
226 foo.map_or(|| {
227 Ok(SomeStruct {
228 f1: 0,
229 f2: 0,
230 f3: 0,
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(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx),
264 _ => func(
265 x,
266 yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
267 zzz,
268 ),
269 }
270}
271
272fn issue_1862() {
273 foo(
274 /* bar = */ None,
275 something_something,
276 /* baz = */ None,
277 /* This comment waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay too long to be kept on the same line */
278 None,
279 /* com */
280 this_last_arg_is_tooooooooooooooooooooooooooooooooo_long_to_be_kept_with_the_pre_comment,
281 )
282}
283
284fn issue_3025() {
285 foo(
286 // This describes the argument below.
287 /* bar = */ None,
288 // This describes the argument below.
289 something_something,
290 // This describes the argument below. */
291 None,
292 // This describes the argument below.
293 /* This comment waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay too long to be kept on the same line */
294 None,
295 // This describes the argument below.
296 /* com */
297 this_last_arg_is_tooooooooooooooooooooooooooooooooo_long_to_be_kept_with_the_pre_comment,
298 )
299}
300
301fn issue_1878() {
302 let channel: &str = seq
303 .next_element()?
304 .ok_or_else(|| de::Error::invalid_length(2, &self))?;
305}