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