Skip to content

unnamed_fields allows unnamed enum variants which behave oddly #130331

Open
@CAD97

Description

@CAD97

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 adaff53)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-unnamed_fields`#![feature(unnamed_fields)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-incomplete-featuresThis issue requires the use of incomplete features.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions