-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Guarantee that it is sound to observe the bytes of None::<P>
where P
is a pointer type subject to NPO
#117591
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
Guarantee that it is sound to observe the bytes of None::<P>
where P
is a pointer type subject to NPO
#117591
Comments
Cc @rust-lang/opsem For thin pointer this seems perfectly fine, I am just not sure where to best document it. I think for wide pointers, this is actually not true today (and seems unlikely to ever be true) -- the discriminant will be stored in one of the two "fields" of the pointer, which means that for |
Sounds good. Put up a PR to guarantee this for thin pointers: #137323 |
No that's not what that PR did? It just talks specifically about transmuting And similarly, looking at what you did in the new PR, it doesn't seem to match the issue description. The PR only guarantees that |
Good point; updated the issue text.
Yeah, I realized the ptr-to-int issue and decided to stick with the more limited (and hopefully less controversial) |
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
Uh oh!
There was an error while loading. Please reload this page.
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 if all of the bytes ofP
are initialized, then all of the bytes ofNone::<P>
(and thus all of the bytes of anyOption<P>
) are initialized. For example, this would allow zerocopy to support safe transmutation fromOption<P>
to[u8; N]
(google/zerocopy#596).I'm opening this issue first rather than a PR so there's an opportunity to discuss whether this is something we want, how it would be best to document it, etc.
The text was updated successfully, but these errors were encountered: