-
Notifications
You must be signed in to change notification settings - Fork 596
Empty repr(Rust) enums are ZSTs #2293
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
842f993
c04b973
5c79307
19075c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,6 +211,8 @@ r[glossary.uninhabited] | |
|
|
||
| A type is uninhabited if it has no constructors and therefore can never be instantiated. An uninhabited type is "empty" in the sense that there are no values of the type. The canonical example of an uninhabited type is the [never type] `!`, or an enum with no variants `enum Never { }`. Opposite of [Inhabited](#inhabited). | ||
|
|
||
| > [!NOTE] Uninhabited types are not necessarily [zero-sized][glossary.zst]. For example, `enum Never { }` is uninhabited and zero-sized, but `(u8, Never)` is uninhabited and not zero-sized. | ||
|
|
||
| r[glossary.zst] | ||
| ### Zero-sized type (ZST) | ||
|
|
||
|
|
@@ -223,6 +225,7 @@ A type is zero sized (a ZST) if its size is 0. Such types have at most one possi | |
| - `repr(Rust)` [structs] with no fields or where all fields are zero sized (see [layout.repr.rust.struct-zst]). | ||
| - `repr(C)` [structs] with no fields or where all fields are zero-sized (see [layout.repr.c.struct.size-field-offset]). | ||
| - `repr(transparent)` [structs] with no fields or where all fields are zero-sized (see [layout.repr.transparent.layout-abi]). | ||
| - `repr(Rust)` [enums] (without a [primitive representation] specified) with no variants (see [layout.repr.rust.enum-empty-zst]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I was looking at the list in the glossary, actually ^^ - sorry for any potential confusion by not including a more precise reference to what I was talking about.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By having
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in #2309 |
||
| - `repr(Rust)` [enums] (without a [primitive representation] specified) with a single [field-struct-like variant], a single [unit-struct-like variant], or a single [tuple-struct-like variant] and where the struct-like thing has no fields or where all of the fields are zero sized (see [layout.repr.rust.enum-struct-like-zst]). | ||
| - [Arrays] of zero-sized types (see [layout.array]). | ||
| - [Arrays] of length zero (see [layout.array]). | ||
|
|
@@ -284,6 +287,8 @@ enum E5 { | |
| enum E6 { | ||
| V1 (), | ||
| } | ||
| # /// An enum with no variants. | ||
| enum E7 {} | ||
|
|
||
| assert_eq!(0, size_of::<()>()); | ||
| assert_eq!(0, size_of_val(&f)); | ||
|
|
@@ -304,6 +309,7 @@ assert_eq!(0, size_of::<E3>()); | |
| assert_eq!(0, size_of::<E4>()); | ||
| assert_eq!(0, size_of::<E5>()); | ||
| assert_eq!(0, size_of::<E6>()); | ||
| assert_eq!(0, size_of::<E7>()); | ||
| ``` | ||
|
|
||
| [`extern` blocks]: items.extern | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.