Structs with no fields or all-ZST fields are ZSTs#2262
Open
DanielEScherzer wants to merge 2 commits intorust-lang:masterfrom
Open
Structs with no fields or all-ZST fields are ZSTs#2262DanielEScherzer wants to merge 2 commits intorust-lang:masterfrom
DanielEScherzer 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
Contributor
|
cc @RalfJung @rust-lang/opsem |
theemathas
reviewed
May 6, 2026
| 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]. |
Contributor
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.
Member
|
That seems reasonable to me (specifically for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.