-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Guarantee behavior of transmuting Option::<T>::None
subject to NPO
#137323
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
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 |
Option::<T>::None
subject to NPO
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. |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Ah, I missed the fact that I'm the reviewer here. ;) |
Rollup of 6 pull requests Successful merges: - #137323 (Guarantee behavior of transmuting `Option::<T>::None` subject to NPO) - #139254 (std: sys: net: uefi: Implement TCP4 connect) - #141432 (refactor `CanonicalVarKind`) - #141480 (document some -Z flags as living in the rustc-dev-guide) - #141486 (rustdoc book: add argument explanation for `html_playground_url`) - #141496 (Enable `[issue-links]` and `[no-mentions]` in triagebot) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #137323 - joshlf:transmute-npo, r=RalfJung Guarantee behavior of transmuting `Option::<T>::None` subject to NPO In #115333, we added a guarantee that transmuting from `[0u8; N]` to `Option<P>` is sound where `P` is a pointer type subject to the null pointer optimization (NPO). It would be useful to be able to guarantee the inverse - that a `None::<P>` value can be transmutes to an array and that will yield `[0u8; N]`. Closes #117591
Guarantee behavior of transmuting `Option::<T>::None` subject to NPO In rust-lang#115333, we added a guarantee that transmuting from `[0u8; N]` to `Option<P>` is sound where `P` is a pointer type subject to the null pointer optimization (NPO). It would be useful to be able to guarantee the inverse - that a `None::<P>` value can be transmutes to an array and that will yield `[0u8; N]`. Closes rust-lang#117591
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