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