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