-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Allow single-value enum types to have size 0 #15747
Comments
I'm filing this just as a possibility for future optimization. It doesn't have to be a high priority, since any use cases for this could probably be fulfilled by an empty struct instead. |
This makes an enum like `enum Foo { Foo }` be zero-sized. If a discriminant is set to non-zero, it still treats it as a c-like enum. Fixes rust-lang#15747
Triage: no change. |
|
I'm nominating for the lang team to decide -- we should confirm that we want this before compiler team implements. |
Discussed in @rust-lang/lang -- If the enum is not |
I'd say this doesn't have to force non-zero-size either, only |
I think any univariant fieldless enum which is not |
Treat repr(Rust) univariant fieldless enums as ZSTs This makes all those enums be represented the same way: ```rust enum A1 { B1 } enum A2 { B2 = 0 } enum A3 { B3, C3(!) } ``` Related to #15747. Cc @rust-lang/wg-codegen @rust-lang/lang
…#15747) This makes all those enums be represented the same way: ```rust enum A1 { B1 } enum A2 { B2 = 0 } enum A3 { B3, C3(!) } ```
Since type
Foo
has only one value, it could have size zero. (This is already the case for single-valued struct types likestruct Foo;
.)Open question: If this change is made, should
Foo as uint
still evaluate to0
in the example above?Note: It would still be possible to force a non-zero size using
[#repr(...)]
orenum Foo { Foo = 1 }
.The text was updated successfully, but these errors were encountered: