Gracefully recover from incorrectly nested items #66127
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-parser
Area: The lexing & 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.
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/:
gives
when instead it could give a single error saying
enum definitions cannot be nested
, or something to that effect.The text was updated successfully, but these errors were encountered: