I don't think this is intended; unnamed fields are described for struct and union, but not for enum.
A built-in derived trait implementation appears to work as long as only a single unnamed variant exists, but more than one unnamed variant usually (but not always) results in errors (e.g. non-exhaustive patterns or attempting to use the wrong kind of variant).
These should probably just be forbidden. There's probably no harm in allowing the syntax, but semantically unnamed variants don't make any real sense. Maybe they could in an “inline the variants” manner, but that very much isn't the currently observed behavior.
Example:
I don't think this is intended; unnamed fields are described for
struct
andunion
, but not forenum
.A built-in derived trait implementation appears to work as long as only a single unnamed variant exists, but more than one unnamed variant usually (but not always) results in errors (e.g. non-exhaustive patterns or attempting to use the wrong kind of variant).
These should probably just be forbidden. There's probably no harm in allowing the syntax, but semantically unnamed variants don't make any real sense. Maybe they could in an “inline the variants” manner, but that very much isn't the currently observed behavior.
Meta
rustc 1.83.0-nightly (2024-09-12 adaff5368b0c7b328a03)
@rustbot label: +F-unnamed-fields +requires-incomplete-features