]> git.lizzy.rs Git - rust.git/blob - src/tools/rustfmt/tests/source/unions.rs
Rollup merge of #107166 - petrochenkov:nooptable, r=oli-obk
[rust.git] / src / tools / rustfmt / tests / source / unions.rs
1 // rustfmt-normalize_comments: true
2 // rustfmt-wrap_comments: true
3
4                                                                        /// A Doc comment
5 #[AnAttribute]
6 pub union 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 union Foo {
20     #[doc(hidden)]
21     // This will NOT get deleted!
22     bar: String, // hi
23 }
24
25 // #1029
26 union 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 union Writebatch<K: Key> {
35     #[allow(dead_code)] //only used for holding the internal pointer
36     writebatch: RawWritebatch,
37     marker: PhantomData<K>,
38 }
39
40 // With a where-clause and generics.
41 pub union Foo<'a, Y: Baz>
42     where X: Whatever
43 {
44     f: SomeType, // Comment beside a field
45 }
46
47 union Baz {
48
49     a: A,  // Comment A
50     b: B, // Comment B
51     c: C,   // Comment C
52
53 }
54
55 union Baz {
56     a: A,  // Comment A
57
58     b: B, // Comment B
59
60
61
62
63     c: C,   // Comment C
64 }
65
66 union Baz {
67
68     a: A,
69
70     b: B,
71     c: C,
72
73
74
75     
76     d: D
77
78 }
79
80 union Baz
81 {
82     // Comment A
83     a: A,
84     
85     // Comment B
86 b: B,
87     // Comment C
88       c: C,}
89
90 pub union State<F: FnMut() -> time::Timespec> { now: F }
91
92 pub union State<F: FnMut() -> ()> { now: F }
93
94 pub union State<F: FnMut()> { now: F }
95
96 union Palette { /// A map of indices in the palette to a count of pixels in approximately that color
97                     foo: i32}
98
99 // Splitting a single line comment into a block previously had a misalignment
100 // when the field had attributes
101 union FieldsWithAttributes {
102     // Pre Comment
103     #[rustfmt::skip] pub host:String, // Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB
104     //Another pre comment
105     #[attr1]
106     #[attr2] pub id: usize // CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCC CCCCCCCCCCCC
107 }
108
109 union Deep {
110     deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep: node::Handle<IdRef<'id, Node<K, V>>,
111                                                      Type,
112                                                      NodeType>,
113 }
114
115 mod m {
116     union X<T> where T: Sized {
117         a: T,
118     }
119 }
120
121 union Issue677 {
122     pub ptr: *const libc::c_void,
123     pub trace: fn(  obj: 
124           *const libc::c_void, tracer   : *mut   JSTracer   ),
125 }
126
127 union Foo {}
128 union Foo {
129     }
130 union Foo {
131     // comment
132     }
133 union Foo {
134     // trailing space ->    
135
136
137     }
138 union Foo { /* comment */ }
139
140 union LongUnion {
141     a: A,
142     the_quick_brown_fox_jumps_over_the_lazy_dog:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
143 }
144
145 union Deep {
146     deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep: node::Handle<IdRef<'id, Node<Key, Value>>,
147                                                                          Type,
148                                                                          NodeType>,
149 }
150
151 // #1364
152 fn foo() {
153     convex_shape.set_point(0, &Vector2f { x: 400.0, y: 100.0 });
154     convex_shape.set_point(1, &Vector2f { x: 500.0, y: 70.0 });
155     convex_shape.set_point(2, &Vector2f { x: 450.0, y: 100.0 });
156     convex_shape.set_point(3, &Vector2f { x: 580.0, y: 150.0 });
157 }
158
159 // Vertical alignment
160 union Foo {
161     aaaaa: u32, // a
162
163     b: u32, // b
164     cc: u32, // cc
165
166     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 1
167     yy: u32, // comment2
168     zzz: u32, // comment3
169
170     aaaaaa: u32, // comment4
171     bb: u32, // comment5
172     // separate
173     dd: u32, // comment7
174     c: u32, // comment6
175
176     aaaaaaa: u32, /* multi
177      * line
178      * comment
179      */
180     b: u32, // hi
181
182     do_not_push_this_comment1: u32, // comment1
183     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
184     please_do_not_push_this_comment3: u32, // comment3
185
186     do_not_push_this_comment1: u32, // comment1
187     // separate
188     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
189     please_do_not_push_this_comment3: u32, // comment3
190
191     do_not_push_this_comment1: u32, // comment1
192     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: u32, // 2
193     // separate
194     please_do_not_push_this_comment3: u32, // comment3
195 }