-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
dropck unsoundness: unions are ignored #52786
Comments
Pretty recent regression. |
Not without recently discussed guarantees on union validity :) |
No, that's not at all what I was saying. We were discussing basic layout invariants. These are invariants the compiler knows about and exploits for enum layout optimizations; violating them is insta-UB. For example, a reference must be non-NULL and aligned. Even a reference being valid is already not covered here as it cannot expressed in terms of just its bit pattern. However, for private fields, types may have arbitrary additional invariants. I hope we agree that the layout invariant for This is an example for an extra invariant that the compiler does not know about, that the data structure upholds through privacy and that unsafe code in this module can hence rely on. |
@RalfJung |
unions are not always trivially dropable Fixes #52786 r? @nikomatsakis
So it turns out that this is a problem: The following code should be rejected by dropck, but it compiles.
This is a nightly-only (because implementing
Drop
for unions is unstable) soundness issue. I need unsafe code to exploit it, butWrap
above should be a perfectly safe to use type.The text was updated successfully, but these errors were encountered: