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