-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.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
Consider this code:
#![feature(transparent_enums)]
use std::mem::size_of;
fn main() {
#[repr(transparent)]
enum VisibleE8 {
A(u8), B(u8), C(u8), D(u8), E(u8), F(u8), G(u8), H(u8), I(u8), J(u8),
K(u8), L(u8), M(u8), N(u8), O(u8), P(u8), Q(u8), R(u8), S(u8), T(u8),
}
println!("VisibleE8: {}", size_of::<VisibleE8>());
}
When you try to compile this, you get two error diagnostics:
error[E0731]: transparent enum needs exactly one variant, but has 20
--> src/main.rs:7:5
|
7 | enum VisibleE8 {
| ^^^^^^^^^^^^^^ needs exactly one variant, but has 20
8 | A(u8), B(u8), C(u8), D(u8), E(u8), F(u8), G(u8), H(u8), I(u8), J(u8),
| ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
9 | K(u8), L(u8), M(u8), N(u8), O(u8), P(u8), Q(u8), R(u8), S(u8), T(u8),
| ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- too many variants in `main::VisibleE8`
error[E0690]: the variant of a transparent enum needs exactly one non-zero-sized field, but has 20
--> src/main.rs:7:5
|
7 | enum VisibleE8 {
| ^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 20
8 | A(u8), B(u8), C(u8), D(u8), E(u8), F(u8), G(u8), H(u8), I(u8), J(u8),
| -- -- -- -- -- -- -- -- -- -- this field is non-zero-sized
| | | | | | | | | |
| | | | | | | | | this field is non-zero-sized
| | | | | | | | this field is non-zero-sized
| | | | | | | this field is non-zero-sized
| | | | | | this field is non-zero-sized
| | | | | this field is non-zero-sized
| | | | this field is non-zero-sized
| | | this field is non-zero-sized
| | this field is non-zero-sized
| this field is non-zero-sized
9 | K(u8), L(u8), M(u8), N(u8), O(u8), P(u8), Q(u8), R(u8), S(u8), T(u8),
| -- -- -- -- -- -- -- -- -- -- this field is non-zero-sized
| | | | | | | | | |
| | | | | | | | | this field is non-zero-sized
| | | | | | | | this field is non-zero-sized
| | | | | | | this field is non-zero-sized
| | | | | | this field is non-zero-sized
| | | | | this field is non-zero-sized
| | | | this field is non-zero-sized
| | | this field is non-zero-sized
| | this field is non-zero-sized
| this field is non-zero-sized
error: aborting due to 2 previous errors
The first diagnostic is exactly describing the problem.
The second diagnostic is irrelevant, and arguably confusing (at least in my mental model of enums, the field count of one variant should be considered independently of the counts for all of the enum's other variants).
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.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.