2022-06-11 00:12:57 -05:00
|
|
|
use std::mem::ManuallyDrop;
|
2020-10-04 15:24:14 -05:00
|
|
|
|
2017-05-17 16:22:52 -05:00
|
|
|
union U1 { // OK
|
2016-08-26 11:23:42 -05:00
|
|
|
a: u8,
|
|
|
|
}
|
2016-08-18 10:31:47 -05:00
|
|
|
|
2017-05-17 16:22:52 -05:00
|
|
|
union U2<T: Copy> { // OK
|
|
|
|
a: T,
|
|
|
|
}
|
|
|
|
|
2020-10-04 15:24:14 -05:00
|
|
|
union U22<T> { // OK
|
2022-06-11 00:12:57 -05:00
|
|
|
a: ManuallyDrop<T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
union U23<T> { // OK
|
|
|
|
a: (ManuallyDrop<T>, i32),
|
2020-10-04 15:24:14 -05:00
|
|
|
}
|
|
|
|
|
2022-06-19 11:57:07 -05:00
|
|
|
union U24<T> { // OK
|
|
|
|
a: [ManuallyDrop<T>; 2],
|
|
|
|
}
|
|
|
|
|
2020-10-04 15:24:14 -05:00
|
|
|
union U3 {
|
2023-03-07 16:26:52 -06:00
|
|
|
a: String, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
|
2017-05-17 16:22:52 -05:00
|
|
|
}
|
|
|
|
|
2022-06-29 21:33:18 -05:00
|
|
|
union U32 { // field that does not drop but is not `Copy`, either
|
2023-03-07 16:26:52 -06:00
|
|
|
a: std::cell::RefCell<i32>, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
|
2020-10-04 15:24:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
union U4<T> {
|
2023-03-07 16:26:52 -06:00
|
|
|
a: T, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
|
2017-05-17 16:22:52 -05:00
|
|
|
}
|
|
|
|
|
2020-10-04 15:24:14 -05:00
|
|
|
union U5 { // Having a drop impl is OK
|
2017-05-17 16:22:52 -05:00
|
|
|
a: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for U5 {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
|
2022-06-11 00:12:57 -05:00
|
|
|
union U5Nested { // a nested union that drops is NOT OK
|
2023-03-07 16:26:52 -06:00
|
|
|
nest: U5, //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
|
2022-06-11 00:12:57 -05:00
|
|
|
}
|
|
|
|
|
2022-06-30 09:17:49 -05:00
|
|
|
union U5Nested2 { // for now we don't special-case empty arrays
|
2023-03-07 16:26:52 -06:00
|
|
|
nest: [U5; 0], //~ ERROR field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
|
2022-06-30 09:17:49 -05:00
|
|
|
}
|
|
|
|
|
2022-06-11 00:12:57 -05:00
|
|
|
union U6 { // OK
|
|
|
|
s: &'static i32,
|
|
|
|
m: &'static mut i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
union U7<T> { // OK
|
|
|
|
f: (&'static mut i32, ManuallyDrop<T>, i32),
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:17:49 -05:00
|
|
|
union U8<T> { // OK
|
|
|
|
f1: [(&'static mut i32, i32); 8],
|
|
|
|
f2: [ManuallyDrop<T>; 2],
|
|
|
|
}
|
|
|
|
|
2016-08-18 10:31:47 -05:00
|
|
|
fn main() {}
|