Skip to content

Using a tuple-like data type with a record-like pattern (or vice versa) produces an opaque diagnostic #41314

Closed
@whitequark

Description

@whitequark

One of the ways to reproduce:

enum X {
    Y(u32)
}

fn main() {
    match X::Y(0) {
        X::Y { data } => ()
    }
}

This results in:

error[E0026]: variant `X::Y` does not have a field named `data`
 --> <anon>:7:16
  |
7 |         X::Y { data } => ()
  |                ^^^^ variant `X::Y` does not have field `data`

error[E0027]: pattern does not mention field `0`
 --> <anon>:7:9
  |
7 |         X::Y { data } => ()
  |         ^^^^^^^^^^^^^ missing field `0`

I think the error message would have been much better if it just said outright that variant X::Y requires a tuple pattern or something like that (I'm not sure what the proper terminology is...)

This happens fairly often during refactoring.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions