2022-06-29 21:33:18 -05:00
|
|
|
use std::mem::ManuallyDrop;
|
2016-08-26 08:54:58 -05:00
|
|
|
|
|
|
|
// Non-copy
|
|
|
|
struct A;
|
|
|
|
struct B;
|
|
|
|
|
|
|
|
union U {
|
2022-06-29 21:33:18 -05:00
|
|
|
a: ManuallyDrop<A>,
|
|
|
|
b: ManuallyDrop<B>,
|
2016-08-26 08:54:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
{
|
2022-06-29 21:33:18 -05:00
|
|
|
let mut u = U { a: ManuallyDrop::new(A) };
|
2016-08-26 08:54:58 -05:00
|
|
|
let a = u.a;
|
2019-04-22 02:40:08 -05:00
|
|
|
let a = u.a; //~ ERROR use of moved value: `u`
|
2016-08-26 08:54:58 -05:00
|
|
|
}
|
|
|
|
{
|
2022-06-29 21:33:18 -05:00
|
|
|
let mut u = U { a: ManuallyDrop::new(A) };
|
2016-08-26 08:54:58 -05:00
|
|
|
let a = u.a;
|
2022-06-29 21:33:18 -05:00
|
|
|
u.a = ManuallyDrop::new(A);
|
2016-08-26 08:54:58 -05:00
|
|
|
let a = u.a; // OK
|
|
|
|
}
|
|
|
|
{
|
2022-06-29 21:33:18 -05:00
|
|
|
let mut u = U { a: ManuallyDrop::new(A) };
|
2016-08-26 08:54:58 -05:00
|
|
|
let a = u.a;
|
2022-06-29 21:33:18 -05:00
|
|
|
u.b = ManuallyDrop::new(B);
|
2016-08-26 08:54:58 -05:00
|
|
|
let a = u.a; // OK
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|