]> git.lizzy.rs Git - rust.git/blob - tests/target/configs-struct_field_align_threshold-20.rs
Format source codes
[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>(
77     pub i32,
78     SomeType, // inline comment
79     T, // sup
80 );
81
82 struct 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
98 struct Tuple(
99     // Comment 1
100     AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
101     // Comment 2
102     BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
103 );
104
105 // With a where clause and generics.
106 pub struct Foo<'a, Y: Baz>
107 where
108     X: Whatever,
109 {
110     f: SomeType, // Comment beside a field
111 }
112
113 struct Baz {
114     a: A, // Comment A
115     b: B, // Comment B
116     c: C, // Comment C
117 }
118
119 struct Baz {
120     a: A, // Comment A
121
122     b: B, // Comment B
123
124     c: C, // Comment C
125 }
126
127 struct Baz {
128     a: A,
129
130     b: B,
131     c: C,
132
133     d: D,
134 }
135
136 struct 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?
147 struct Tuple(
148     A, // Comment
149     B,
150 );
151
152 pub struct State<F: FnMut() -> time::Timespec> {
153     now: F,
154 }
155
156 pub struct State<F: FnMut() -> ()> {
157     now: F,
158 }
159
160 pub struct State<F: FnMut()> {
161     now: F,
162 }
163
164 struct Palette {
165     /// A map of indizes 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
172 struct 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
183 struct Deep {
184     deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep:
185         node::Handle<IdRef<'id, Node<K, V>>, Type, NodeType>,
186 }
187
188 struct Foo<T>(T);
189 struct Foo<T>(T)
190 where
191     T: Copy,
192     T: Eq;
193 struct Foo<T>(
194     TTTTTTTTTTTTTTTTT,
195     UUUUUUUUUUUUUUUUUUUUUUUU,
196     TTTTTTTTTTTTTTTTTTT,
197     UUUUUUUUUUUUUUUUUUU,
198 );
199 struct Foo<T>(
200     TTTTTTTTTTTTTTTTTT,
201     UUUUUUUUUUUUUUUUUUUUUUUU,
202     TTTTTTTTTTTTTTTTTTT,
203 )
204 where
205     T: PartialEq;
206 struct Foo<T>(
207     TTTTTTTTTTTTTTTTT,
208     UUUUUUUUUUUUUUUUUUUUUUUU,
209     TTTTTTTTTTTTTTTTTTTTT,
210 )
211 where
212     T: PartialEq;
213 struct Foo<T>(
214     TTTTTTTTTTTTTTTTT,
215     UUUUUUUUUUUUUUUUUUUUUUUU,
216     TTTTTTTTTTTTTTTTTTT,
217     UUUUUUUUUUUUUUUUUUU,
218 )
219 where
220     T: PartialEq;
221 struct Foo<T>(
222     TTTTTTTTTTTTTTTTT, // Foo
223     UUUUUUUUUUUUUUUUUUUUUUUU, // Bar
224     // Baz
225     TTTTTTTTTTTTTTTTTTT,
226     // Qux (FIXME #572 - doc comment)
227     UUUUUUUUUUUUUUUUUUU,
228 );
229
230 mod m {
231     struct X<T>
232     where
233         T: Sized,
234     {
235         a: T,
236     }
237 }
238
239 struct Foo<T>(
240     TTTTTTTTTTTTTTTTTTT,
241     /// Qux
242     UUUUUUUUUUUUUUUUUUU,
243 );
244
245 struct Issue677 {
246     pub ptr:   *const libc::c_void,
247     pub trace: fn(obj: *const libc::c_void, tracer: *mut JSTracer),
248 }
249
250 struct Foo {}
251 struct Foo {}
252 struct Foo {
253     // comment
254 }
255 struct Foo {
256     // trailing space ->
257 }
258 struct Foo { /* comment */ }
259 struct Foo( /* comment */ );
260
261 struct LongStruct {
262     a: A,
263     the_quick_brown_fox_jumps_over_the_lazy_dog:
264         AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
265 }
266
267 struct Deep {
268     deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep:
269         node::Handle<IdRef<'id, Node<Key, Value>>, Type, NodeType>,
270 }
271
272 struct Foo<C = ()>(String);
273
274 // #1364
275 fn foo() {
276     convex_shape.set_point(0, &Vector2f { x: 400.0, y: 100.0 });
277     convex_shape.set_point(1, &Vector2f { x: 500.0, y: 70.0 });
278     convex_shape.set_point(2, &Vector2f { x: 450.0, y: 100.0 });
279     convex_shape.set_point(3, &Vector2f { x: 580.0, y: 150.0 });
280 }
281
282 fn main() {
283     let x = Bar;
284
285     // Comment
286     let y = Foo { a: x };
287
288     Foo {
289         a: foo(), // comment
290         // comment
291         b: bar(),
292         ..something
293     };
294
295     Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b() };
296
297     Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
298         a: f(),
299         b: b(),
300     };
301
302     Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
303         // Comment
304         a: foo(), // Comment
305         // Comment
306         b: bar(), // Comment
307     };
308
309     Foo { a: Bar, b: f() };
310
311     Quux {
312         x: if cond {
313             bar();
314         },
315         y: baz(),
316     };
317
318     A {
319         // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit
320         // amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante
321         // hendrerit. Donec et mollis dolor.
322         first: item(),
323         // Praesent et diam eget libero egestas mattis sit amet vitae augue.
324         // Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
325         second: Item,
326     };
327
328     Some(Data::MethodCallData(MethodCallData {
329         span:    sub_span.unwrap(),
330         scope:   self.enclosing_scope(id),
331         ref_id:  def_id,
332         decl_id: Some(decl_id),
333     }));
334
335     Diagram {
336         //                 o        This graph demonstrates how
337         //                / \       significant whitespace is
338         //               o   o      preserved.
339         //              /|\   \
340         //             o o o   o
341         graph: G,
342     }
343 }
344
345 fn matcher() {
346     TagTerminatedByteMatcher {
347         matcher: ByteMatcher {
348             pattern: b"<HTML",
349             mask:    b"\xFF\xDF\xDF\xDF\xDF\xFF",
350         },
351     };
352 }
353
354 fn issue177() {
355     struct Foo<T> {
356         memb: T,
357     }
358     let foo = Foo::<i64> { memb: 10 };
359 }
360
361 fn issue201() {
362     let s = S { a: 0, ..b };
363 }
364
365 fn issue201_2() {
366     let s = S { a: S2 { ..c }, ..b };
367 }
368
369 fn issue278() {
370     let s = S {
371         a: 0,
372         //
373         b: 0,
374     };
375     let s1 = S {
376         a: 0,
377         // foo
378         //
379         // bar
380         b: 0,
381     };
382 }
383
384 fn struct_exprs() {
385     Foo { a: 1, b: f(2) };
386     Foo {
387         a: 1,
388         b: f(2),
389         ..g(3)
390     };
391     LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongStruct {
392         ..base
393     };
394     IntrinsicISizesContribution {
395         content_intrinsic_sizes: IntrinsicISizes {
396             minimum_inline_size: 0,
397         },
398     };
399 }
400
401 fn issue123() {
402     Foo { a: b, c: d, e: f };
403
404     Foo {
405         a: bb,
406         c: dd,
407         e: ff,
408     };
409
410     Foo {
411         a: ddddddddddddddddddddd,
412         b: cccccccccccccccccccccccccccccccccccccc,
413     };
414 }
415
416 fn issue491() {
417     Foo {
418         guard: None,
419         arm:   0, // Comment
420     };
421
422     Foo {
423         arm: 0, // Comment
424     };
425
426     Foo {
427         a: aaaaaaaaaa,
428         b: bbbbbbbb,
429         c: cccccccccc,
430         d: dddddddddd, // a comment
431         e: eeeeeeeee,
432     };
433 }
434
435 fn issue698() {
436     Record {
437         ffffffffffffffffffffffffffields: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
438     };
439     Record {
440         ffffffffffffffffffffffffffields:
441             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
442     }
443 }
444
445 fn issue835() {
446     MyStruct {};
447     MyStruct { /* a comment */ };
448     MyStruct {
449         // Another comment
450     };
451     MyStruct {}
452 }
453
454 fn field_init_shorthand() {
455     MyStruct { x, y, z };
456     MyStruct { x, y, z, ..base };
457     Foo {
458         aaaaaaaaaa,
459         bbbbbbbb,
460         cccccccccc,
461         dddddddddd, // a comment
462         eeeeeeeee,
463     };
464     Record {
465         ffffffffffffffffffffffffffieldsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
466     };
467 }