Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign updefault representation for enum discriminant should be i32 #24290
Comments
This comment has been minimized.
This comment has been minimized.
|
triage: P-backcompat-lang (1.0) |
rust-highfive
added
the
P-backcompat-lang
label
Apr 10, 2015
rust-highfive
added this to the 1.0 milestone
Apr 10, 2015
pnkfelix
self-assigned this
Apr 10, 2015
brson
removed this from the 1.0 milestone
Apr 24, 2015
brson
added
P-medium
and removed
P-backcompat-lang
labels
Apr 24, 2015
This comment has been minimized.
This comment has been minimized.
|
Not happening for 1.0. Hopefully can be done backwards-compatibly later. |
This was referenced Feb 25, 2016
brson
added
T-lang
A-typesystem
I-nominated
labels
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Triage: old issue. Lot's has happened around enums since. @rust-lang/lang what do? |
This comment has been minimized.
This comment has been minimized.
|
cc @durka |
This comment has been minimized.
This comment has been minimized.
|
@eddyb checked into this; we currently choose the repr based on the value range, so we're closing as resolved. |
aturon
closed this
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
It... doesn't look like this was ever actually fixed? enum En {
V1 = 0xFFFF_FFFF_FFFF_FFFF,
}which gives this warning on x86_64:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pnkfelix commentedApr 10, 2015
Spawned off of #24270.
Rust has attempted to support a semantics for enum discriminant representation where, if you did not choose an explicit enum representation, it would infer the appropriate representation to use.
This seems fine as long as one hides that representation from the user, but with intrinsics like
discriminant_value, it becomes a bit problematic, since e.g. it is hard to know what type to use when comparing elements of theenum. (You need to cast it to the right type so that you do not e.g. mistake-1for a large postiive value.)Plus, it turns out that we don't actually do all that much inference at all; a simple experiment like this:
when run with a 32-bit target, reveals that the const-evaluator is only using
isizefor the type anyway, and will not automatically promote toi64.So, after discussing (irc) the matter with @nikomatsakis I think we change things slightly so that at the language level, in terms of what the const-eval does etc, we should just use
i32. (Of course, if you override the choice with#[repr(...)], then we will use that instead.)This would be a breaking change for 64-bit platforms, but arguably what it is really doing is fixing a portability bug that has laid dormant for at least a little while (and perhaps a long while -- its a long story).