2020-10-04 20:24:14 +00:00
|
|
|
// ignore-tidy-linelength
|
2022-06-11 05:12:57 +00:00
|
|
|
use std::mem::ManuallyDrop;
|
2020-10-04 20:24:14 +00:00
|
|
|
|
2017-05-17 21:22:52 +00:00
|
|
|
union U1 { // OK
|
2016-08-26 16:23:42 +00:00
|
|
|
a: u8,
|
|
|
|
}
|
2016-08-18 15:31:47 +00:00
|
|
|
|
2017-05-17 21:22:52 +00:00
|
|
|
union U2<T: Copy> { // OK
|
|
|
|
a: T,
|
|
|
|
}
|
|
|
|
|
2020-10-04 20:24:14 +00:00
|
|
|
union U22<T> { // OK
|
2022-06-11 05:12:57 +00:00
|
|
|
a: ManuallyDrop<T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
union U23<T> { // OK
|
|
|
|
a: (ManuallyDrop<T>, i32),
|
2020-10-04 20:24:14 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 16:57:07 +00:00
|
|
|
union U24<T> { // OK
|
|
|
|
a: [ManuallyDrop<T>; 2],
|
|
|
|
}
|
|
|
|
|
2020-10-04 20:24:14 +00:00
|
|
|
union U3 {
|
2022-02-15 19:16:19 +00:00
|
|
|
a: String, //~ ERROR unions cannot contain fields that may need dropping
|
2017-05-17 21:22:52 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 02:33:18 +00:00
|
|
|
union U32 { // field that does not drop but is not `Copy`, either
|
|
|
|
a: std::cell::RefCell<i32>, //~ ERROR unions cannot contain fields that may need dropping
|
2020-10-04 20:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
union U4<T> {
|
2022-02-15 19:16:19 +00:00
|
|
|
a: T, //~ ERROR unions cannot contain fields that may need dropping
|
2017-05-17 21:22:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 20:24:14 +00:00
|
|
|
union U5 { // Having a drop impl is OK
|
2017-05-17 21:22:52 +00:00
|
|
|
a: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for U5 {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
|
2022-06-11 05:12:57 +00:00
|
|
|
union U5Nested { // a nested union that drops is NOT OK
|
|
|
|
nest: U5, //~ ERROR unions cannot contain fields that may need dropping
|
|
|
|
}
|
|
|
|
|
|
|
|
union U6 { // OK
|
|
|
|
s: &'static i32,
|
|
|
|
m: &'static mut i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
union U7<T> { // OK
|
|
|
|
f: (&'static mut i32, ManuallyDrop<T>, i32),
|
|
|
|
}
|
|
|
|
|
2016-08-18 15:31:47 +00:00
|
|
|
fn main() {}
|