-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
derive: assume enum repr defaults to isize #32253
Conversation
@bors: r+ e45b59aed463c15bd9aadd8280f4a5d49027e73f |
☔ The latest upstream changes (presumably #30587) made this pull request unmergeable. Please resolve the merge conflicts. |
@oli-obk is this fix now irrelevant given your PR? |
well kindof. I actually broke the following construct (explicitly, not accidentally) on 32bit enum Eu64 {
Au64 = 0,
Bu64 = 0x8000_0000_0000_0000
} because on 32bit rustc now errors at compiletime about the collision Once we properly fix the automatic enum discriminant type detection, the issue might appear again. |
@oli-obk can you clarify what it means to properly fix discriminant detection, and what the current situation is? Is deriving correct in assuming that if the repr isn't specified than it will be isize (or smaller)? |
In list form, because I'm confusing myself when I'm writing it in text form.
well... the discriminant should be |
oh.... I only tested on 32 bit... it obviously only collides on 32 bit... So yea, this change is still necessary for 64 bit. |
It was originally intended to be i32, but it isn't. Fixes rust-lang#31886.
Okay, so I changed it back to Note that you can still write a program like this: enum Eu64 {
Au64 = 0,
Bu64 = 0x8000_0000_0000_0001 //~WARN literal out of range for isize
}
fn main() {
println!("{} {} {}", std::mem::size_of::<Eu64>(), Eu64::Au64 as isize, Eu64::Bu64 as isize);
} which prints different answers on 32- and 64-bit ( |
And combined with the fact that I guess that's the price you pay for ignoring the warnings. |
Sorry I've gotten a bit lost with all the changes in flight. Is this ready to go? Did something about constants change how we want to do this? |
@alexcrichton what I believe is that is no longer possible to trigger #31886 on a 32-bit system because @oli-obk's const evaluator will catch the collision. However, my fix (as implemented currently, in this PR!) is still needed to avoid #31886 on 64-bit systems. |
⌛ Testing commit 9d0748f with merge 2ddcf31... |
💔 Test failed - auto-win-msvc-64-opt-rustbuild |
spurious failure
|
@bors: retry |
derive: assume enum repr defaults to isize derive: assume enum repr defaults to isize Fixes #31886. Spawned from #32139. r? @alexcrichton
derive: assume enum repr defaults to isize
Fixes #31886.
Spawned from #32139.
r? @alexcrichton