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