-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-offset_of_nested`#![feature(offset_of_nested)]``#![feature(offset_of_nested)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
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)
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-offset_of_nested`#![feature(offset_of_nested)]``#![feature(offset_of_nested)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.