Skip to content

let-chains parsing is not resilient to stray { between lets #117766

Closed

Description

Code

#![feature(let_chains)]
fn main() {
    if let () = ()
        && let () = () {
        && let () = ()
    {
    }
}

Current output

error: this file contains an unclosed delimiter
 --> src/main.rs:8:2
  |
2 | fn main() {
  |           - unclosed delimiter
3 |     if let () = ()
4 |         && let () = () {
  |                        - this delimiter might not be properly closed...
...
8 | }
  | -^
  | |
  | ...as it matches this but it has different indentation

Desired output

error: this file contains an unclosed delimiter
 --> src/main.rs:8:2
  |
2 | fn main() {
  |           - unclosed delimiter
3 |     if let () = ()
4 |         && let () = () {
  |                        - this delimiter might not be properly closed...
5 |         && let () = ()
  |         -------------- you likely meant to continue the let-chain
...
8 | }
  | -^
  | |
  | ...as it matches this but it has different indentation
help: remove the spurious block start
  |
4 -         && let () = () {
4 +         && let () = ()
  |

Rationale and extra context

Unmatched delimiters are hard to deal with by taking consideration of surrounding code because they actually occur during lexing. Still, it'd be nice if we detected some common sources of issues like this one.

Other cases

No response

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-papercutDiagnostics: An error or lint that needs small tweaks.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.P-lowLow priorityT-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