-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
This code compiles:
#[repr(transparent)] struct Foo {}
Going by the docs for #[repr(transparent)]
:
#[repr(transparent)]
can only be used on a struct or single-variant enum that has a single non-zero-sized field (there may be additional zero-sized fields). The effect is that the layout and ABI of the whole struct/enum is guaranteed to be the same as that one field.
... it seems like the compiler should reject that code, with diagnostics similar to those it emits for an empty transparent enum:
error[E0084]: unsupported representation for zero-variant enum
--> src/lib.rs:2:1
|
2 | #[repr(transparent)] enum E {}
| ^^^^^^^^^^^^^^^^^^^^ ------ zero-variant enum
error[E0731]: transparent enum needs exactly one variant, but has 0
--> src/lib.rs:2:22
|
2 | #[repr(transparent)] enum E {}
| ^^^^^^ needs exactly one variant, but has 0
Some errors have detailed explanations: E0084, E0731.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.