Skip to content

Collect occurrences of {} for mismatched braces diagnostic #63904

Closed
@estebank

Description

@estebank

Many editors helpfully auto close delimiters when writing them down. It is not uncommon for this to cause the following to occur:

fn main() {}
    let _ = ();
}

It'd be a good idea for the parser or lexer to keep track of these empty blocks to provide an error closer to

error: unexpected close delimiter: `}`
 --> src/main.rs:3:1
  |
1 | fn main() {}
  |           -- this block is empty, you might have not meant to close it
2 |     let _ = ();
3 | }
  | ^ unexpected close delimiter

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.E-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