Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Gracefully recover from incorrectly nested items #66127

Closed
estebank opened this issue Nov 5, 2019 · 0 comments · Fixed by #66641
Closed

Gracefully recover from incorrectly nested items #66127

estebank opened this issue Nov 5, 2019 · 0 comments · Fixed by #66641
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Nov 5, 2019

The parser currently only attempts to parse items and sub-items based on what the parent item is and pretty much gives up if, for example, a trait item is inside of an ADT, or an ADT is defined inside an ADT. The parser could try exhausting all the valid possible parses, and if it fails start trying to parse other cases that are invalid there and explain why it is not allowed and supply guidance on what to do instead. For example, a case taken from https://www.reddit.com/r/rust/comments/5tnjt8/question_regarding_nested_enum/:

enum Foo {
    enum Bar {
         Baz,
     },
    Bat,
}

gives

error: expected identifier, found keyword `enum`
 --> src/lib.rs:2:5
  |
2 |     enum Bar {
  |     ^^^^ expected identifier, found keyword
  |
help: you can escape reserved keywords to use them as identifiers
  |
2 |     r#enum Bar {
  |     ^^^^^^

error: missing comma
 --> src/lib.rs:2:9
  |
2 |     enum Bar {
  |         ^ help: missing comma

error: expected `:`, found `,`
 --> src/lib.rs:3:13
  |
3 |          Baz,
  |             ^ expected `:`

when instead it could give a single error saying enum definitions cannot be nested, or something to that effect.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. A-parser Area: The parsing of Rust source code to an AST labels Nov 5, 2019
@bors bors closed this as completed in 980ccaa Nov 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant