Skip to content

Suggest ; on parse error when applicable #87197

Closed
@estebank

Description

@estebank

Given the following code:

fn main() {
    let x = 100;
    println!("{}", x)
    let y = 200;
    println!("{}", y)
}

The current output is:

error: expected one of `.`, `;`, `?`, `}`, or an operator, found keyword `let`
 --> src/main.rs:4:5
  |
3 |     println!("{}", x)
  |                      - expected one of `.`, `;`, `?`, `}`, or an operator
4 |     let y = 200;
  |     ^^^ unexpected token

We should detect cases where a semicolon would be appropriate (probe that the current token and maybe limited lookahead confirm that what comes next could be a valid statement on its own) and suggest a semicolon. If there is a missing }, we already suggest that it might belong there. We might want to silence one or the other depending on whether the current token might be starting a statement or an item (let vs struct, etc.).

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions