-
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
Enums with only one variant and without #[repr(_)] have size 0 in 1.27 beta #50830
Comments
cc @nox |
That was expected, I just don't think those |
That transmute was allowed on stable though. Would it be possible to revert the 0-size if a number is attached to the variant? At the moment,
|
That’s true, but all 3 of these crates using transmute this way are unsound and allow those transmute calls to be reached from safe code with values which aren’t the actual single discriminant anyway. Even if we revert that patch, those are bugs that should be fixed.
AFAIK transmute being allowed on things with no explicit representation has always been icky.
|
One such unsound transmute was the cause for one of the regressions from #45225, where an integer was transmuted to an |
Also, all such problem can be fixed "locally", by adding a |
Some discussion from IRC: https://botbot.me/mozilla/rustc/2018-05-17/?msg=100159968&page=1 |
Discussed in the @rust-lang/compiler meeting at or around this point in the IRC log. The current consensus is:
Because these crates have no reverse dependencies, patching is relatively easy -- only new versions are needed. @polachok, @meqif, and @vinipsmaker: we would be very happy to help you rewrite the relevant code if needed! Let us know what help you may need! |
Closing this as won't fix then. |
I fully agree with the prevailing viewpoint that transmuting was undefined behavior, and that it really shouldn't be used. In fact, this issue came up before and I fixed it in a later version of utp — I'm not sure why an older version of the crate was targeted here. |
Crater tests always the latest version of every crate, and also an older version for some of them. |
Note that previous changes have also "broken" UB transmutes, such as |
Some crates are defining enums with only one variant without using
#[repr(_)]
, and in 1.27 beta those enums have size 0. This breaks those crates when they use transmute though.An easy fix for those crates is adding the appropriate
#[repr()]
attribute to the enums, but we might want to revert the change to avoid breaking compatibility.The text was updated successfully, but these errors were encountered: