]> git.lizzy.rs Git - rust.git/blob - tests/source/structs.rs
Update tests
[rust.git] / tests / source / structs.rs
1 // rustfmt-normalize_comments: true
2 // rustfmt-wrap_comments: true
3
4                                                                        /// A Doc comment
5 #[AnAttribute]
6 pub struct Foo {
7     #[rustfmt_skip]
8     f :   SomeType, // Comment beside a field
9     f: SomeType, // Comment beside a field
10     // Comment on a field
11     #[AnAttribute]
12     g: SomeOtherType,
13       /// A doc comment on a field
14     h: AThirdType,
15     pub i: TypeForPublicField
16 }
17
18 // #1029
19 pub struct Foo {
20     #[doc(hidden)]
21     // This will NOT get deleted!
22     bar: String, // hi
23 }
24
25 // #1029
26 struct X {
27     // `x` is an important number.
28     #[allow(unused)] // TODO: use
29     x: u32,
30 }
31
32 // #410
33 #[allow(missing_docs)]
34 pub struct Writebatch<K: Key> {
35     #[allow(dead_code)] //only used for holding the internal pointer
36     writebatch: RawWritebatch,
37     marker: PhantomData<K>,
38 }
39
40 struct Bar;
41
42 struct NewType(Type,       OtherType);
43
44 struct
45 NewInt     <T: Copy>(pub i32, SomeType /* inline comment */, T /* sup */
46
47
48     );
49
50 struct Qux<'a,
51            N: Clone + 'a,
52            E: Clone + 'a,
53            G: Labeller<'a, N, E> + GraphWalk<'a, N, E>,
54            W: Write + Copy>
55 (
56     AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, // Comment
57     BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
58     #[AnAttr]
59     // Comment
60     /// Testdoc
61     G,
62     pub W,
63 );
64
65 struct Tuple(/*Comment 1*/ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
66              /* Comment 2   */ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,);
67
68 // With a where clause and generics.
69 pub struct Foo<'a, Y: Baz>
70     where X: Whatever
71 {
72     f: SomeType, // Comment beside a field
73 }
74
75 struct Baz {
76
77     a: A,  // Comment A
78     b: B, // Comment B
79     c: C,   // Comment C
80
81 }
82
83 struct Baz {
84     a: A,  // Comment A
85
86     b: B, // Comment B
87
88
89
90
91     c: C,   // Comment C
92 }
93
94 struct Baz {
95
96     a: A,
97
98     b: B,
99     c: C,
100
101
102
103     
104     d: D
105
106 }
107
108 struct Baz
109 {
110     // Comment A
111     a: A,
112     
113     // Comment B
114 b: B,
115     // Comment C
116       c: C,}
117
118 // Will this be a one-liner?
119 struct Tuple(
120     A, //Comment
121     B
122 );
123
124 pub struct State<F: FnMut() -> time::Timespec> { now: F }
125
126 pub struct State<F: FnMut() -> ()> { now: F }
127
128 pub struct State<F: FnMut()> { now: F }
129
130 struct Palette { /// A map of indizes in the palette to a count of pixels in approximately that color
131                     foo: i32}
132
133 // Splitting a single line comment into a block previously had a misalignment
134 // when the field had attributes
135 struct FieldsWithAttributes {
136     // Pre Comment
137     #[rustfmt_skip] pub host:String, // Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB
138     //Another pre comment
139     #[attr1]
140     #[attr2] pub id: usize // CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCC CCCCCCCCCCCC
141 }
142
143 struct Deep {
144     deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep: node::Handle<IdRef<'id, Node<K, V>>,
145                                                      Type,
146                                                      NodeType>,
147 }
148
149 struct Foo<T>(T);
150 struct Foo<T>(T) where T: Copy, T: Eq;
151 struct Foo<T>(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUU);
152 struct Foo<T>(TTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT) where T: PartialEq;
153 struct Foo<T>(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTTTT) where T: PartialEq;
154 struct Foo<T>(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUU) where T: PartialEq;
155 struct Foo<T>(TTTTTTTTTTTTTTTTT, // Foo
156               UUUUUUUUUUUUUUUUUUUUUUUU /* Bar */,
157               // Baz
158               TTTTTTTTTTTTTTTTTTT,
159               // Qux (FIXME #572 - doc comment)
160               UUUUUUUUUUUUUUUUUUU);
161
162 mod m {
163     struct X<T> where T: Sized {
164         a: T,
165     }
166 }
167
168 struct Foo<T>(TTTTTTTTTTTTTTTTTTT,
169               /// Qux
170     UUUUUUUUUUUUUUUUUUU);
171
172 struct Issue677 {
173     pub ptr: *const libc::c_void,
174     pub trace: fn(  obj: 
175           *const libc::c_void, tracer   : *mut   JSTracer   ),
176 }
177
178 struct Foo {}
179 struct Foo {
180     }
181 struct Foo {
182     // comment
183     }
184 struct Foo {
185     // trailing space ->    
186
187
188     }
189 struct Foo { /* comment */ }
190 struct Foo( /* comment */ );
191
192 struct LongStruct {
193     a: A,
194     the_quick_brown_fox_jumps_over_the_lazy_dog:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
195 }
196
197 struct Deep {
198     deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep: node::Handle<IdRef<'id, Node<Key, Value>>,
199                                                                          Type,
200                                                                          NodeType>,
201 }
202
203 struct Foo<C=()>(String);
204
205 // #1364
206 fn foo() {
207     convex_shape.set_point(0, &Vector2f { x: 400.0, y: 100.0 });
208     convex_shape.set_point(1, &Vector2f { x: 500.0, y: 70.0 });
209     convex_shape.set_point(2, &Vector2f { x: 450.0, y: 100.0 });
210     convex_shape.set_point(3, &Vector2f { x: 580.0, y: 150.0 });
211 }
212
213 // Vertical alignment
214 struct Foo {
215     aaaaa: u32, // a
216
217     b: u32, // b
218     cc: u32, // cc
219
220     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 1
221     yy: u32, // comment2
222     zzz: u32, // comment3
223
224     aaaaaa: u32, // comment4
225     bb: u32, // comment5
226     // separate
227     dd: u32, // comment7
228     c: u32, // comment6
229
230     aaaaaaa: u32, /* multi
231      * line
232      * comment
233      */
234     b: u32, // hi
235
236     do_not_push_this_comment1: u32, // comment1
237     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
238     please_do_not_push_this_comment3: u32, // comment3
239
240     do_not_push_this_comment1: u32, // comment1
241     // separate
242     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
243     please_do_not_push_this_comment3: u32, // comment3
244
245     do_not_push_this_comment1: u32, // comment1
246     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
247     // separate
248     please_do_not_push_this_comment3: u32, // comment3
249 }
250
251 // structs with long identifier
252 struct Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong {}
253 struct Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong {}
254 struct Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong {}
255 struct Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong { x: i32 }