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