Structs with no fields or all-ZST fields are ZSTs#2262
Structs with no fields or all-ZST fields are ZSTs#2262DanielEScherzer wants to merge 2 commits intorust-lang:masterfrom
Conversation
ba89b4f to
51e8478
Compare
51e8478 to
9c34b1e
Compare
9c34b1e to
6a2c83a
Compare
6a2c83a to
5011dcd
Compare
|
cc @RalfJung @rust-lang/opsem |
| For [structs] with no fields, or where all fields are [zero-sized], it is further guaranteed that the structs are themselves [zero-sized]. | ||
|
|
||
| r[layout.repr.rust.enum-struct-like-zst] | ||
| For [enums] (without a primitive representation specified) with a single struct-like variant with no fields or where all fields are [zero-sized], the enum itself is [zero-sized]. |
There was a problem hiding this comment.
Seems bizarre to guarantee this for struct-like variants but not unit-like variants or tuple-like variants.
|
That seems reasonable to me (specifically for |
|
We talked about this in the lang call today. Let's propose to do this with the correction that, for enums, we mean those @rfcbot fcp merge lang |
|
Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
@rfcbot concern check-randomize-layout |
|
This seems stronger than what we guarantee for non-ZST structs, which require I don't see a reason not to make this guarantee, and it seems like a useful one, so let's do it. @rfcbot reviewed |
Guarantee that structs with Rust representation and with no fields, or where all fields are ZSTs, are themselves ZSTs.
Guarantee that enums with Rust representation with a single struct-like variant with no fields, or where all fields are ZSTs, are themselves ZSTs.