Skip to content

Suboptimal error in case of duplicate , in struct constructor #50974

Closed
@oli-obk

Description

@oli-obk
struct Foo {
    a: i32,
    b: i32,
}

fn main() {
    let x = Foo {
        a: 42,,
        b: 3,
    };
}

results in

error: expected identifier, found `,`
 --> src/main.rs:9:15
  |
8 |     let x = Foo {
  |             --- while parsing this struct
9 |         a: 42,,
  |               ^ expected identifier

error[E0063]: missing field `b` in initializer of `Foo`
 --> src/main.rs:8:13
  |
8 |     let x = Foo {
  |             ^^^ missing `b`

we may want to add a parser recovery that just reports the error, eats the comma and continues parsing as normally

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions