-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guarantee behavior of transmuting Option::<T>::None subject to NPO #137323
base: master
Are you sure you want to change the base?
Conversation
r? libs-api (since this is making a behavior guaranteed) |
Cc @rust-lang/opsem @rust-lang/lang This will need a t-lang FCP. @joshlf would be good to write a summary for t-lang, knowing that they will lack all the context we have here. :) |
Looking at the PR itself, the change LGTM. |
Currently, zerocopy has the ability to validate at runtime whether a This works via our Eventually, we'd like to not only support going from #[repr(C)]
struct T {
a: u8,
b: u16,
}
#[repr(C)]
struct U {
a: bool,
b: u16,
} Since That gets us to this PR: In order to make this change, for each type that currently implements |
In #115333, we added a guarantee that transmuting from
[0u8; N]
toOption<P>
is sound whereP
is a pointer type subject to the null pointer optimization (NPO). It would be useful to be able to guarantee the inverse - that aNone::<P>
value can be transmutes to an array and that will yield[0u8; N]
.Closes #117591