Closed
Description
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.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: The lexing & parsing of Rust source code to an ASTArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: Confusing error or lint; hard to understand for new users.Low priorityRelevant to the compiler team, which will review and decide on the PR/issue.