rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.88k stars 12.52k forks source link

unnamed_fields allows unnamed enum variants which behave oddly #130331

Open CAD97 opened 5 days ago

CAD97 commented 5 days ago

Example:

enum E {
    _,
    _ = 1,
    _(),
    _ {},
}

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.

Meta

rustc 1.83.0-nightly (2024-09-12 adaff5368b0c7b328a03)

@rustbot label: +F-unnamed-fields +requires-incomplete-features

CAD97 commented 5 days ago

@rustbot modify labels: +F-unnamed-fields +requires-incomplete-features

Well I guess I forgot how to use rustbot labels whoops and can't look it up again just yet