]>
Commit | Line | Data |
---|---|---|
064997fb FG |
1 | use std::mem::ManuallyDrop; |
2 | ||
3 | union U1 { // OK | |
4 | a: u8, | |
5 | } | |
6 | ||
7 | union U2<T: Copy> { // OK | |
8 | a: T, | |
9 | } | |
10 | ||
11 | union U22<T> { // OK | |
12 | a: ManuallyDrop<T>, | |
13 | } | |
14 | ||
15 | union U23<T> { // OK | |
16 | a: (ManuallyDrop<T>, i32), | |
17 | } | |
18 | ||
19 | union U24<T> { // OK | |
20 | a: [ManuallyDrop<T>; 2], | |
21 | } | |
22 | ||
23 | union U3 { | |
24 | a: String, //~ ERROR unions cannot contain fields that may need dropping | |
25 | } | |
26 | ||
27 | union U32 { // field that does not drop but is not `Copy`, either | |
28 | a: std::cell::RefCell<i32>, //~ ERROR unions cannot contain fields that may need dropping | |
29 | } | |
30 | ||
31 | union U4<T> { | |
32 | a: T, //~ ERROR unions cannot contain fields that may need dropping | |
33 | } | |
34 | ||
35 | union U5 { // Having a drop impl is OK | |
36 | a: u8, | |
37 | } | |
38 | ||
39 | impl Drop for U5 { | |
40 | fn drop(&mut self) {} | |
41 | } | |
42 | ||
43 | union U5Nested { // a nested union that drops is NOT OK | |
44 | nest: U5, //~ ERROR unions cannot contain fields that may need dropping | |
45 | } | |
46 | ||
47 | union U5Nested2 { // for now we don't special-case empty arrays | |
48 | nest: [U5; 0], //~ ERROR unions cannot contain fields that may need dropping | |
49 | } | |
50 | ||
51 | union U6 { // OK | |
52 | s: &'static i32, | |
53 | m: &'static mut i32, | |
54 | } | |
55 | ||
56 | union U7<T> { // OK | |
57 | f: (&'static mut i32, ManuallyDrop<T>, i32), | |
58 | } | |
59 | ||
60 | union U8<T> { // OK | |
61 | f1: [(&'static mut i32, i32); 8], | |
62 | f2: [ManuallyDrop<T>; 2], | |
63 | } | |
64 | ||
65 | fn main() {} |