2019-11-04 00:00:00 +00:00
|
|
|
// check-pass
|
2018-11-05 13:35:30 +00:00
|
|
|
|
2022-06-30 02:33:18 +00:00
|
|
|
use std::mem::ManuallyDrop;
|
2018-11-05 13:35:30 +00:00
|
|
|
|
|
|
|
struct A;
|
|
|
|
struct B;
|
|
|
|
|
|
|
|
union U {
|
2022-06-30 02:33:18 +00:00
|
|
|
a: ManuallyDrop<A>,
|
|
|
|
b: ManuallyDrop<B>,
|
2018-11-05 13:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
{
|
2022-06-30 02:33:18 +00:00
|
|
|
let mut u = U { a: ManuallyDrop::new(A) };
|
2018-11-05 13:35:30 +00:00
|
|
|
let a = u.a;
|
2022-06-30 02:33:18 +00:00
|
|
|
u.a = ManuallyDrop::new(A);
|
2018-11-05 13:35:30 +00:00
|
|
|
let a = u.a; // OK
|
|
|
|
}
|
|
|
|
{
|
2022-06-30 02:33:18 +00:00
|
|
|
let mut u = U { a: ManuallyDrop::new(A) };
|
2018-11-05 13:35:30 +00:00
|
|
|
let a = u.a;
|
2022-06-30 02:33:18 +00:00
|
|
|
u.b = ManuallyDrop::new(B);
|
2018-11-05 13:35:30 +00:00
|
|
|
let a = u.a; // OK
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|