mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 03:03:40 +00:00
58 lines
1011 B
Rust
58 lines
1011 B
Rust
// ignore-tidy-linelength
|
|
use std::mem::ManuallyDrop;
|
|
|
|
union U1 { // OK
|
|
a: u8,
|
|
}
|
|
|
|
union U2<T: Copy> { // OK
|
|
a: T,
|
|
}
|
|
|
|
union U22<T> { // OK
|
|
a: ManuallyDrop<T>,
|
|
}
|
|
|
|
union U23<T> { // OK
|
|
a: (ManuallyDrop<T>, i32),
|
|
}
|
|
|
|
union U24<T> { // OK
|
|
a: [ManuallyDrop<T>; 2],
|
|
}
|
|
|
|
union U3 {
|
|
a: String, //~ ERROR unions cannot contain fields that may need dropping
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
union U4<T> {
|
|
a: T, //~ ERROR unions cannot contain fields that may need dropping
|
|
}
|
|
|
|
union U5 { // Having a drop impl is OK
|
|
a: u8,
|
|
}
|
|
|
|
impl Drop for U5 {
|
|
fn drop(&mut self) {}
|
|
}
|
|
|
|
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),
|
|
}
|
|
|
|
fn main() {}
|