Skip to content

Gracefully handle missing comma between struct style enum variants #56579

Closed
@estebank

Description

@estebank

The following code should gracefully recover from parse error, provide an appropriate suggestion and continue to typechk:

enum Foo {
    Bar {
    }
    /// doc
    Qux {
    }
    Quz,
}
fn main() {
    let x: usize = Foo::Quz;
}
error: expected one of `,` or `}`, found `/// doc`
 --> src/lib.rs:4:5
  |
3 |     }
  |      - help: missing comma here
4 |     /// doc
  |     ^^^^^^^ unexpected token

error: expected one of `,` or `}`, found `Quz`
 --> src/lib.rs:7:5
  |
6 |     }
  |      - help: missing comma here
7 |     Quz,
  |     ^^^ unexpected token

error[E0308]: mismatched types
  --> src/main.rs:10:20
   |
10 |     let x: usize = Foo::Quz;
   |                    ^^^^^^^^ expected usize, found enum `Foo`
   |
   = note: expected type `usize`
              found type `Foo`

If this could be generalized to all "unexpected token" cases, even better, but that might get tricky.

CC #48724.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions