]> git.proxmox.com Git - rustc.git/blame - src/tools/rustfmt/tests/target/configs/struct_field_align_threshold/20.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / rustfmt / tests / target / configs / struct_field_align_threshold / 20.rs
CommitLineData
f20569fa
XL
1// rustfmt-struct_field_align_threshold: 20
2// rustfmt-normalize_comments: true
3// rustfmt-wrap_comments: true
4// rustfmt-error_on_line_overflow: false
5
6struct Foo {
7 x: u32,
8 yy: u32, // comment
9 zzz: u32,
10}
11
12pub struct Bar {
13 x: u32,
14 yy: u32,
15 zzz: u32,
16
17 xxxxxxx: u32,
18}
19
20fn main() {
21 let foo = Foo {
22 x: 0,
23 yy: 1,
24 zzz: 2,
25 };
26
27 let bar = Bar {
28 x: 0,
29 yy: 1,
30 zzz: 2,
31
32 xxxxxxx: 3,
33 };
34}
35
36/// A Doc comment
37#[AnAttribute]
38pub struct Foo {
39 #[rustfmt::skip]
40 f : SomeType, // Comment beside a field
41 f: SomeType, // Comment beside a field
42 // Comment on a field
43 #[AnAttribute]
44 g: SomeOtherType,
45 /// A doc comment on a field
46 h: AThirdType,
47 pub i: TypeForPublicField,
48}
49
50// #1029
51pub struct Foo {
52 #[doc(hidden)]
53 // This will NOT get deleted!
54 bar: String, // hi
55}
56
57// #1029
58struct X {
59 // `x` is an important number.
60 #[allow(unused)] // TODO: use
61 x: u32,
62}
63
64// #410
65#[allow(missing_docs)]
66pub struct Writebatch<K: Key> {
67 #[allow(dead_code)] // only used for holding the internal pointer
68 writebatch: RawWritebatch,
69 marker: PhantomData<K>,
70}
71
72struct Bar;
73
74struct NewType(Type, OtherType);
75
76struct NewInt<T: Copy>(
77 pub i32,
78 SomeType, // inline comment
79 T, // sup
80);
81
82struct Qux<
83 'a,
84 N: Clone + 'a,
85 E: Clone + 'a,
86 G: Labeller<'a, N, E> + GraphWalk<'a, N, E>,
87 W: Write + Copy,
88>(
89 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, // Comment
90 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
91 #[AnAttr]
92 // Comment
93 /// Testdoc
94 G,
95 pub W,
96);
97
98struct Tuple(
99 // Comment 1
100 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
101 // Comment 2
102 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
103);
104
105// With a where-clause and generics.
106pub struct Foo<'a, Y: Baz>
107where
108 X: Whatever,
109{
110 f: SomeType, // Comment beside a field
111}
112
113struct Baz {
114 a: A, // Comment A
115 b: B, // Comment B
116 c: C, // Comment C
117}
118
119struct Baz {
120 a: A, // Comment A
121
122 b: B, // Comment B
123
124 c: C, // Comment C
125}
126
127struct Baz {
128 a: A,
129
130 b: B,
131 c: C,
132
133 d: D,
134}
135
136struct Baz {
137 // Comment A
138 a: A,
139
140 // Comment B
141 b: B,
142 // Comment C
143 c: C,
144}
145
146// Will this be a one-liner?
147struct Tuple(
148 A, // Comment
149 B,
150);
151
152pub struct State<F: FnMut() -> time::Timespec> {
153 now: F,
154}
155
156pub struct State<F: FnMut() -> ()> {
157 now: F,
158}
159
160pub struct State<F: FnMut()> {
161 now: F,
162}
163
164struct Palette {
165 /// A map of indices in the palette to a count of pixels in approximately
166 /// that color
167 foo: i32,
168}
169
170// Splitting a single line comment into a block previously had a misalignment
171// when the field had attributes
172struct FieldsWithAttributes {
173 // Pre Comment
174 #[rustfmt::skip] pub host:String, /* Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB
175 * BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB */
176 // Another pre comment
177 #[attr1]
178 #[attr2]
179 pub id: usize, /* CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCC
180 * CCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCC CCCCCCCCCCCC */
181}
182
183struct Deep {
184 deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep:
185 node::Handle<IdRef<'id, Node<K, V>>, Type, NodeType>,
186}
187
188struct Foo<T>(T);
189struct Foo<T>(T)
190where
191 T: Copy,
192 T: Eq;
193struct Foo<T>(
194 TTTTTTTTTTTTTTTTT,
195 UUUUUUUUUUUUUUUUUUUUUUUU,
196 TTTTTTTTTTTTTTTTTTT,
197 UUUUUUUUUUUUUUUUUUU,
198);
199struct Foo<T>(
200 TTTTTTTTTTTTTTTTTT,
201 UUUUUUUUUUUUUUUUUUUUUUUU,
202 TTTTTTTTTTTTTTTTTTT,
203)
204where
205 T: PartialEq;
206struct Foo<T>(
207 TTTTTTTTTTTTTTTTT,
208 UUUUUUUUUUUUUUUUUUUUUUUU,
209 TTTTTTTTTTTTTTTTTTTTT,
210)
211where
212 T: PartialEq;
213struct Foo<T>(
214 TTTTTTTTTTTTTTTTT,
215 UUUUUUUUUUUUUUUUUUUUUUUU,
216 TTTTTTTTTTTTTTTTTTT,
217 UUUUUUUUUUUUUUUUUUU,
218)
219where
220 T: PartialEq;
221struct Foo<T>(
222 TTTTTTTTTTTTTTTTT, // Foo
223 UUUUUUUUUUUUUUUUUUUUUUUU, // Bar
224 // Baz
225 TTTTTTTTTTTTTTTTTTT,
226 // Qux (FIXME #572 - doc comment)
227 UUUUUUUUUUUUUUUUUUU,
228);
229
230mod m {
231 struct X<T>
232 where
233 T: Sized,
234 {
235 a: T,
236 }
237}
238
239struct Foo<T>(
240 TTTTTTTTTTTTTTTTTTT,
241 /// Qux
242 UUUUUUUUUUUUUUUUUUU,
243);
244
245struct Issue677 {
246 pub ptr: *const libc::c_void,
247 pub trace: fn(obj: *const libc::c_void, tracer: *mut JSTracer),
248}
249
250struct Foo {}
251struct Foo {}
252struct Foo {
253 // comment
254}
255struct Foo {
256 // trailing space ->
257}
258struct Foo {
259 // comment
260}
261struct Foo(
262 // comment
263);
264
265struct LongStruct {
266 a: A,
267 the_quick_brown_fox_jumps_over_the_lazy_dog:
268 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
269}
270
271struct Deep {
272 deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep:
273 node::Handle<IdRef<'id, Node<Key, Value>>, Type, NodeType>,
274}
275
276struct Foo<C = ()>(String);
277
278// #1364
279fn foo() {
280 convex_shape.set_point(0, &Vector2f { x: 400.0, y: 100.0 });
281 convex_shape.set_point(1, &Vector2f { x: 500.0, y: 70.0 });
282 convex_shape.set_point(2, &Vector2f { x: 450.0, y: 100.0 });
283 convex_shape.set_point(3, &Vector2f { x: 580.0, y: 150.0 });
284}
285
286fn main() {
287 let x = Bar;
288
289 // Comment
290 let y = Foo { a: x };
291
292 Foo {
293 a: foo(), // comment
294 // comment
295 b: bar(),
296 ..something
297 };
298
299 Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b() };
300
301 Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
302 a: f(),
303 b: b(),
304 };
305
306 Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
307 // Comment
308 a: foo(), // Comment
309 // Comment
310 b: bar(), // Comment
311 };
312
313 Foo { a: Bar, b: f() };
314
315 Quux {
316 x: if cond {
317 bar();
318 },
319 y: baz(),
320 };
321
322 A {
323 // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit
324 // amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante
325 // hendrerit. Donec et mollis dolor.
326 first: item(),
327 // Praesent et diam eget libero egestas mattis sit amet vitae augue.
328 // Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
329 second: Item,
330 };
331
332 Some(Data::MethodCallData(MethodCallData {
333 span: sub_span.unwrap(),
334 scope: self.enclosing_scope(id),
335 ref_id: def_id,
336 decl_id: Some(decl_id),
337 }));
338
339 Diagram {
340 // o This graph demonstrates how
341 // / \ significant whitespace is
342 // o o preserved.
343 // /|\ \
344 // o o o o
345 graph: G,
346 }
347}
348
349fn matcher() {
350 TagTerminatedByteMatcher {
351 matcher: ByteMatcher {
352 pattern: b"<HTML",
353 mask: b"\xFF\xDF\xDF\xDF\xDF\xFF",
354 },
355 };
356}
357
358fn issue177() {
359 struct Foo<T> {
360 memb: T,
361 }
362 let foo = Foo::<i64> { memb: 10 };
363}
364
365fn issue201() {
366 let s = S { a: 0, ..b };
367}
368
369fn issue201_2() {
370 let s = S { a: S2 { ..c }, ..b };
371}
372
373fn issue278() {
374 let s = S {
375 a: 0,
376 //
377 b: 0,
378 };
379 let s1 = S {
380 a: 0,
381 // foo
382 //
383 // bar
384 b: 0,
385 };
386}
387
388fn struct_exprs() {
389 Foo { a: 1, b: f(2) };
390 Foo {
391 a: 1,
392 b: f(2),
393 ..g(3)
394 };
395 LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongStruct {
396 ..base
397 };
398 IntrinsicISizesContribution {
399 content_intrinsic_sizes: IntrinsicISizes {
400 minimum_inline_size: 0,
401 },
402 };
403}
404
405fn issue123() {
406 Foo { a: b, c: d, e: f };
407
408 Foo {
409 a: bb,
410 c: dd,
411 e: ff,
412 };
413
414 Foo {
415 a: ddddddddddddddddddddd,
416 b: cccccccccccccccccccccccccccccccccccccc,
417 };
418}
419
420fn issue491() {
421 Foo {
422 guard: None,
423 arm: 0, // Comment
424 };
425
426 Foo {
427 arm: 0, // Comment
428 };
429
430 Foo {
431 a: aaaaaaaaaa,
432 b: bbbbbbbb,
433 c: cccccccccc,
434 d: dddddddddd, // a comment
435 e: eeeeeeeee,
436 };
437}
438
439fn issue698() {
440 Record {
441 ffffffffffffffffffffffffffields: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
442 };
443 Record {
444 ffffffffffffffffffffffffffields:
445 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
446 }
447}
448
449fn issue835() {
450 MyStruct {};
451 MyStruct { /* a comment */ };
452 MyStruct {
453 // Another comment
454 };
455 MyStruct {}
456}
457
458fn field_init_shorthand() {
459 MyStruct { x, y, z };
460 MyStruct { x, y, z, ..base };
461 Foo {
462 aaaaaaaaaa,
463 bbbbbbbb,
464 cccccccccc,
465 dddddddddd, // a comment
466 eeeeeeeee,
467 };
468 Record {
469 ffffffffffffffffffffffffffieldsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
470 };
471}