Skip to content

Gracefully handle missing comma between struct style enum variants #56579

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
estebank opened this issue Dec 7, 2018 · 1 comment
Closed

Gracefully handle missing comma between struct style enum variants #56579

estebank opened this issue Dec 7, 2018 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST

Comments

@estebank
Copy link
Contributor

estebank commented Dec 7, 2018

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.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST labels Dec 7, 2018
@estebank
Copy link
Contributor Author

estebank commented Dec 7, 2018

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

bors added a commit that referenced this issue Mar 22, 2019
Recover from missing comma between enum variants and from bad `pub` kw

Fix #56579. Fix #56473.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST
Projects
None yet
Development

No branches or pull requests

1 participant