Skip to content

Gracefully handle missing comma between struct style enum variants #56579

Closed
@estebank

Description

@estebank
Contributor

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.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-parserArea: The lexing & parsing of Rust source code to an AST
on Dec 7, 2018
estebank

estebank commented on Dec 7, 2018

@estebank
ContributorAuthor

This should also handle the tuple variants case (enum E { V(usize) Foo }).

added a commit that references this issue on Mar 22, 2019

Auto merge of #59031 - estebank:recover-from-comaless, r=petrochenkov

a85ec7c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @estebank

        Issue actions

          Gracefully handle missing comma between struct style enum variants · Issue #56579 · rust-lang/rust