]> git.lizzy.rs Git - rust.git/blob - tests/target/structs.rs
Merge pull request #3576 from rchaser53/issue-3567
[rust.git] / tests / target / 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 // #1095
19 struct S<T /* comment */> {
20     t: T,
21 }
22
23 // #1029
24 pub struct Foo {
25     #[doc(hidden)]
26     // This will NOT get deleted!
27     bar: String, // hi
28 }
29
30 // #1029
31 struct X {
32     // `x` is an important number.
33     #[allow(unused)] // TODO: use
34     x: u32,
35 }
36
37 // #410
38 #[allow(missing_docs)]
39 pub struct Writebatch<K: Key> {
40     #[allow(dead_code)] // only used for holding the internal pointer
41     writebatch: RawWritebatch,
42     marker: PhantomData<K>,
43 }
44
45 struct Bar;
46
47 struct NewType(Type, OtherType);
48
49 struct NewInt<T: Copy>(
50     pub i32,
51     SomeType, // inline comment
52     T,        // sup
53 );
54
55 struct Qux<
56     'a,
57     N: Clone + 'a,
58     E: Clone + 'a,
59     G: Labeller<'a, N, E> + GraphWalk<'a, N, E>,
60     W: Write + Copy,
61 >(
62     AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, // Comment
63     BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
64     #[AnAttr]
65     // Comment
66     /// Testdoc
67     G,
68     pub W,
69 );
70
71 struct Tuple(
72     // Comment 1
73     AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
74     // Comment 2
75     BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
76 );
77
78 // With a where-clause and generics.
79 pub struct Foo<'a, Y: Baz>
80 where
81     X: Whatever,
82 {
83     f: SomeType, // Comment beside a field
84 }
85
86 struct Baz {
87     a: A, // Comment A
88     b: B, // Comment B
89     c: C, // Comment C
90 }
91
92 struct Baz {
93     a: A, // Comment A
94
95     b: B, // Comment B
96
97     c: C, // Comment C
98 }
99
100 struct Baz {
101     a: A,
102
103     b: B,
104     c: C,
105
106     d: D,
107 }
108
109 struct Baz {
110     // Comment A
111     a: A,
112
113     // Comment B
114     b: B,
115     // Comment C
116     c: C,
117 }
118
119 // Will this be a one-liner?
120 struct Tuple(
121     A, // Comment
122     B,
123 );
124
125 pub struct State<F: FnMut() -> time::Timespec> {
126     now: F,
127 }
128
129 pub struct State<F: FnMut() -> ()> {
130     now: F,
131 }
132
133 pub struct State<F: FnMut()> {
134     now: F,
135 }
136
137 struct Palette {
138     /// A map of indices in the palette to a count of pixels in approximately
139     /// that color
140     foo: i32,
141 }
142
143 // Splitting a single line comment into a block previously had a misalignment
144 // when the field had attributes
145 struct FieldsWithAttributes {
146     // Pre Comment
147     #[rustfmt::skip] pub host:String, /* Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB
148                                        * BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB */
149     // Another pre comment
150     #[attr1]
151     #[attr2]
152     pub id: usize, /* CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCC
153                     * CCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCC CCCCCCCCCCCC */
154 }
155
156 struct Deep {
157     deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep:
158         node::Handle<IdRef<'id, Node<K, V>>, Type, NodeType>,
159 }
160
161 struct Foo<T>(T);
162 struct Foo<T>(T)
163 where
164     T: Copy,
165     T: Eq;
166 struct Foo<T>(
167     TTTTTTTTTTTTTTTTT,
168     UUUUUUUUUUUUUUUUUUUUUUUU,
169     TTTTTTTTTTTTTTTTTTT,
170     UUUUUUUUUUUUUUUUUUU,
171 );
172 struct Foo<T>(
173     TTTTTTTTTTTTTTTTTT,
174     UUUUUUUUUUUUUUUUUUUUUUUU,
175     TTTTTTTTTTTTTTTTTTT,
176 )
177 where
178     T: PartialEq;
179 struct Foo<T>(
180     TTTTTTTTTTTTTTTTT,
181     UUUUUUUUUUUUUUUUUUUUUUUU,
182     TTTTTTTTTTTTTTTTTTTTT,
183 )
184 where
185     T: PartialEq;
186 struct Foo<T>(
187     TTTTTTTTTTTTTTTTT,
188     UUUUUUUUUUUUUUUUUUUUUUUU,
189     TTTTTTTTTTTTTTTTTTT,
190     UUUUUUUUUUUUUUUUUUU,
191 )
192 where
193     T: PartialEq;
194 struct Foo<T>(
195     TTTTTTTTTTTTTTTTT,        // Foo
196     UUUUUUUUUUUUUUUUUUUUUUUU, // Bar
197     // Baz
198     TTTTTTTTTTTTTTTTTTT,
199     // Qux (FIXME #572 - doc comment)
200     UUUUUUUUUUUUUUUUUUU,
201 );
202
203 mod m {
204     struct X<T>
205     where
206         T: Sized,
207     {
208         a: T,
209     }
210 }
211
212 struct Foo<T>(
213     TTTTTTTTTTTTTTTTTTT,
214     /// Qux
215     UUUUUUUUUUUUUUUUUUU,
216 );
217
218 struct Issue677 {
219     pub ptr: *const libc::c_void,
220     pub trace: fn(obj: *const libc::c_void, tracer: *mut JSTracer),
221 }
222
223 struct Foo {}
224 struct Foo {}
225 struct Foo {
226     // comment
227 }
228 struct Foo {
229     // trailing space ->
230 }
231 struct Foo {
232     // comment
233 }
234 struct Foo(
235     // comment
236 );
237
238 struct LongStruct {
239     a: A,
240     the_quick_brown_fox_jumps_over_the_lazy_dog:
241         AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
242 }
243
244 struct Deep {
245     deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep:
246         node::Handle<IdRef<'id, Node<Key, Value>>, Type, NodeType>,
247 }
248
249 struct Foo<C = ()>(String);
250
251 // #1364
252 fn foo() {
253     convex_shape.set_point(0, &Vector2f { x: 400.0, y: 100.0 });
254     convex_shape.set_point(1, &Vector2f { x: 500.0, y: 70.0 });
255     convex_shape.set_point(2, &Vector2f { x: 450.0, y: 100.0 });
256     convex_shape.set_point(3, &Vector2f { x: 580.0, y: 150.0 });
257 }
258
259 // Vertical alignment
260 struct Foo {
261     aaaaa: u32, // a
262
263     b: u32,  // b
264     cc: u32, // cc
265
266     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 1
267     yy: u32,  // comment2
268     zzz: u32, // comment3
269
270     aaaaaa: u32, // comment4
271     bb: u32,     // comment5
272     // separate
273     dd: u32, // comment7
274     c: u32,  // comment6
275
276     aaaaaaa: u32, /* multi
277                    * line
278                    * comment
279                    */
280     b: u32, // hi
281
282     do_not_push_this_comment1: u32, // comment1
283     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
284     please_do_not_push_this_comment3: u32, // comment3
285
286     do_not_push_this_comment1: u32, // comment1
287     // separate
288     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
289     please_do_not_push_this_comment3: u32, // comment3
290
291     do_not_push_this_comment1: u32, // comment1
292     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
293     // separate
294     please_do_not_push_this_comment3: u32, // comment3
295 }
296
297 // structs with long identifier
298 struct Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
299 {}
300 struct Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
301 {}
302 struct Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
303 {}
304 struct Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
305 {
306     x: i32,
307 }
308
309 // structs with visibility, do not duplicate visibility (#2110).
310 pub(self) struct Foo {}
311 pub(super) struct Foo {}
312 pub(crate) struct Foo {}
313 pub(self) struct Foo();
314 pub(super) struct Foo();
315 pub(crate) struct Foo();
316
317 // #2125
318 pub struct ReadinessCheckRegistry(
319     Mutex<HashMap<Arc<String>, Box<Fn() -> ReadinessCheck + Sync + Send>>>,
320 );
321
322 // #2144 unit struct with generics
323 struct MyBox<T: ?Sized>;
324 struct MyBoxx<T, S>
325 where
326     T: ?Sized,
327     S: Clone;
328
329 // #2208
330 struct Test {
331     /// foo
332     #[serde(default)]
333     pub join: Vec<String>,
334     #[serde(default)]
335     pub tls: bool,
336 }
337
338 // #2818
339 struct Paren((i32))
340 where
341     i32: Trait;
342 struct Parens((i32, i32))
343 where
344     i32: Trait;