Open
Description
When a union contains a non-Copy
variant, the compiler forces the user to wrap it in ManuallyDrop
. ManuallyDrop
is guaranteed to have the same layout as the underlying type, but it is opaque to offset_of! because the value
field is private.
here is an example that fails to compile
#![feature(offset_of_nested)]
use core::mem;
struct X { foo: usize }
union N { X: mem::ManuallyDrop<X> }
const o: usize = mem::offset_of!(N, X.value.foo);
playground link: (https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=84fadd9f1808d5ff7b52de9e1f0ab6b4)