]> git.lizzy.rs Git - rust.git/blob - tests/source/structs.rs
handle hard tabs when formatting trailing comments (#3836)
[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 // #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
50 NewInt     <T: Copy>(pub i32, SomeType /* inline comment */, T /* sup */
51
52
53     );
54
55 struct Qux<'a,
56            N: Clone + 'a,
57            E: Clone + 'a,
58            G: Labeller<'a, N, E> + GraphWalk<'a, N, E>,
59            W: Write + Copy>
60 (
61     AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, // Comment
62     BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
63     #[AnAttr]
64     // Comment
65     /// Testdoc
66     G,
67     pub W,
68 );
69
70 struct Tuple(/*Comment 1*/ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
71              /* Comment 2   */ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,);
72
73 // With a where-clause and generics.
74 pub struct Foo<'a, Y: Baz>
75     where X: Whatever
76 {
77     f: SomeType, // Comment beside a field
78 }
79
80 struct Baz {
81
82     a: A,  // Comment A
83     b: B, // Comment B
84     c: C,   // Comment C
85
86 }
87
88 struct Baz {
89     a: A,  // Comment A
90
91     b: B, // Comment B
92
93
94
95
96     c: C,   // Comment C
97 }
98
99 struct Baz {
100
101     a: A,
102
103     b: B,
104     c: C,
105
106
107
108     
109     d: D
110
111 }
112
113 struct Baz
114 {
115     // Comment A
116     a: A,
117     
118     // Comment B
119 b: B,
120     // Comment C
121       c: C,}
122
123 // Will this be a one-liner?
124 struct Tuple(
125     A, //Comment
126     B
127 );
128
129 pub struct State<F: FnMut() -> time::Timespec> { now: F }
130
131 pub struct State<F: FnMut() -> ()> { now: F }
132
133 pub struct State<F: FnMut()> { now: F }
134
135 struct Palette { /// A map of indices in the palette to a count of pixels in approximately that color
136                     foo: i32}
137
138 // Splitting a single line comment into a block previously had a misalignment
139 // when the field had attributes
140 struct FieldsWithAttributes {
141     // Pre Comment
142     #[rustfmt::skip] pub host:String, // Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB
143     //Another pre comment
144     #[attr1]
145     #[attr2] pub id: usize // CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCC CCCCCCCCCCCC
146 }
147
148 struct Deep {
149     deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep: node::Handle<IdRef<'id, Node<K, V>>,
150                                                      Type,
151                                                      NodeType>,
152 }
153
154 struct Foo<T>(T);
155 struct Foo<T>(T) where T: Copy, T: Eq;
156 struct Foo<T>(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUU);
157 struct Foo<T>(TTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT) where T: PartialEq;
158 struct Foo<T>(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTTTT) where T: PartialEq;
159 struct Foo<T>(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUU) where T: PartialEq;
160 struct Foo<T>(TTTTTTTTTTTTTTTTT, // Foo
161               UUUUUUUUUUUUUUUUUUUUUUUU /* Bar */,
162               // Baz
163               TTTTTTTTTTTTTTTTTTT,
164               // Qux (FIXME #572 - doc comment)
165               UUUUUUUUUUUUUUUUUUU);
166
167 mod m {
168     struct X<T> where T: Sized {
169         a: T,
170     }
171 }
172
173 struct Foo<T>(TTTTTTTTTTTTTTTTTTT,
174               /// Qux
175     UUUUUUUUUUUUUUUUUUU);
176
177 struct Issue677 {
178     pub ptr: *const libc::c_void,
179     pub trace: fn(  obj: 
180           *const libc::c_void, tracer   : *mut   JSTracer   ),
181 }
182
183 struct Foo {}
184 struct Foo {
185     }
186 struct Foo {
187     // comment
188     }
189 struct Foo {
190     // trailing space ->    
191
192
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:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
200 }
201
202 struct Deep {
203     deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep: node::Handle<IdRef<'id, Node<Key, Value>>,
204                                                                          Type,
205                                                                          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 }
217
218 // Vertical alignment
219 struct Foo {
220     aaaaa: u32, // a
221
222     b: u32, // b
223     cc: u32, // cc
224
225     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 1
226     yy: u32, // comment2
227     zzz: u32, // comment3
228
229     aaaaaa: u32, // comment4
230     bb: u32, // comment5
231     // separate
232     dd: u32, // comment7
233     c: u32, // comment6
234
235     aaaaaaa: u32, /* multi
236      * line
237      * comment
238      */
239     b: u32, // hi
240
241     do_not_push_this_comment1: u32, // comment1
242     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
243     please_do_not_push_this_comment3: u32, // comment3
244
245     do_not_push_this_comment1: u32, // comment1
246     // separate
247     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
248     please_do_not_push_this_comment3: u32, // comment3
249
250     do_not_push_this_comment1: u32, // comment1
251     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
252     // separate
253     please_do_not_push_this_comment3: u32, // comment3
254 }
255
256 // structs with long identifier
257 struct Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong {}
258 struct Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong {}
259 struct Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong {}
260 struct Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong { x: i32 }
261
262 // structs with visibility, do not duplicate visibility (#2110).
263 pub(in self) struct Foo{}
264 pub(super) struct Foo{}
265 pub(crate) struct Foo{}
266 pub(in self) struct Foo();
267 pub(super) struct Foo();
268 pub(crate) struct Foo();
269
270 // #2125
271 pub struct ReadinessCheckRegistry(Mutex<HashMap<Arc<String>, Box<Fn() -> ReadinessCheck + Sync + Send>>>);
272
273 // #2144 unit struct with generics
274 struct MyBox<T:?Sized>;
275 struct MyBoxx<T, S> where T: ?Sized, S: Clone;
276
277 // #2208
278 struct Test {
279     /// foo
280     #[serde(default)]
281     pub join: Vec<String>,
282     #[serde(default)] pub tls: bool,
283 }
284
285 // #2818
286 struct Paren((i32)) where i32: Trait;
287 struct Parens((i32, i32)) where i32: Trait;