-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Guarantee behavior of transmuting Option::<T>::None
subject to NPO
#137323
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
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 |
This seems consistent with how we already support using |
Per the above, we already have to guarantee this and there'd be widespread breakage if we ever failed to uphold it. So, let's write it down. @rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
@rfcbot reviewed |
Under the restriction (that's in the docs) of the very specific list of NPO types, 100% agreed. @rfcbot reviewed (Just wanted to double-check that we weren't accidentally guaranteeing anything for |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
We talked about this in the lang call today, were happy to see it go forward, and it's now in FCP. Let's cc @rust-lang/spec, to think about the interplay between the Reference and the library documentation when making language guarantees like this. |
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