Skip to content

Incorrect help message in matching structs with .. on both ends #112188

Closed
@lebedev

Description

@lebedev

Code

fn main() {
    struct Foo {
        x: i32,
    }

    let foo = Foo { x: 1 };
    match foo {
        Foo { .., x, .. } => (),
        _ => (),
    }
}

Current output

error: expected `}`, found `,`
 --> src\main.rs:8:17
  |
8 |         Foo { .., x, .. } => (),
  |               --^
  |               | |
  |               | expected `}`
  |               `..` must be at the end and cannot have a trailing comma
  |
help: move the `..` to the end of the field list
  |
8 -         Foo { .., x, .. } => (),
8 +         Foo { .., x,  , .. } => (),
  |

Desired output

The part in help:

8 -         Foo { .., x, .. } => (),
8 +         Foo { x, .. } => (),

Rationale and extra context

A suggestion that can be compiled is better than the one that can't be compiled.

Other cases

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions