-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Union of non-null types should not be non-null #101096
Comments
AFAIK, this is undecided currently - see rust-lang/unsafe-code-guidelines#73 for more background/discussion on how to handle unions. |
This is deliberate, unions are currently by design not having any niches. unions are used to do whacky low-level things with the underlying bytes, and e.g. we do not assume that the list of variants is actually exhaustive -- one might want to add new variants in a future-compatible way later (this is not an uncommon use of unions in C). |
Thanks for the link! I read through pretty much the entire thread. Looks like there's much more to it that I thought. |
I don't think keeping this issue open will have too much value. The validity of unions are tracked on the opsem repo already. Feel free to reopen if you disagree. |
Example
Expected behaviour
Just as
Option<Foo>
andOption<Bar>
have the same size asFoo
andBar
respectively, I expected thatOption<FooBar>
also has the same size asFooBar
. However this does not happen. Adding#[rustc_nonnull_optimization_guaranteed]
does not seem to make a difference.The text was updated successfully, but these errors were encountered: