-
Notifications
You must be signed in to change notification settings - Fork 748
Generate pub const for most of anonymous enums #84
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
Comments
We do this for top-level anonymous enums IIRC (see the |
I guess it is not hard to generate consts, but it might be hard to determine whether an anonymous enum is used like |
FWIW, I want this because in servo/servo#13674, we use a static const from Gecko side, which leads to linking failure on Windows. And I want to either convert that static const to a macro or an enum constant. It seems to me the latter is better because it is scoped. If we can have this enhancement implemented soonish, I would use enum constants for that, otherwise, I'll change it to a macro. |
Anonymous enums usually serve as a container of scoped constants without linkage. It is more useful to have a
pub const
for each of its members, rather than an enum with some unique name.Discussed this with @Manishearth on IRC, and he prefers having enum because that fits matching better. However, in majority of cases, you cannot get a variable with its type being an anonymous enum, which means you need a manual conversion anyway. And that manual conversion requires the knowledge of the name of the enum in binding, which is volatile.
There is one case, though, you can get a variable with an anonymous enum type, that someone writes
enum { XXX } var
, in which case @Manishearth's argument makes lots of sense. So I suggest that for all other cases, we generatepub const
s rather than enums.The text was updated successfully, but these errors were encountered: