-
Notifications
You must be signed in to change notification settings - Fork 60
Do typed copies of unions preserve "invalid" bytes? #555
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
Comments
This is tied up with the broader discussion around the value representation of unions, #438 and #494. I think for unions that look like |
What about the specific question on insta-UB? Is it the case that transmuting I hope it's the latter since we already provide safe APIs for constructing |
I think that's not the question, I think the question is, after you store |
I'm specifically referring to this comment in the original post: // Is it sound to do this? Or insta-UB a la transmuting `3` to `bool`? |
You're changing the question. In OP the first question is transmuting So there would be 4 questions:
|
It's definitely never UB to transmute anything to In an ideal world, transmuting back would always give you exactly what you started with. In practice, there are some hickups, which I am trying to resolve but not everyone agrees that's worth a breaking change; see #518. For types EDIT: oh wait, if |
I've put up rust-lang/rust#140463 to document
What about
|
Validity of |
Okay understood. So, in rust-lang/rust#140463 (comment), it should be valid for me to update the wording to clarify that, so long as |
Let's discuss there. |
For zerocopy, @joshlf and I are interested in whether we can soundly round-trip values through a union that aren't bit-valid instances of a non-ZST field; e.g.:
The reasons for our concern is that we know typed copies don't have to preserve padding, but will they preserve initialized-but-invalid bytes?
The text was updated successfully, but these errors were encountered: