Skip to content

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

Closed

Description

@estebank

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

Activity

  1. added
    E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-parserArea: The lexing & parsing of Rust source code to an AST
    P-lowLow priority
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    D-papercutDiagnostics: An error or lint that needs small tweaks.
    on Nov 9, 2023
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 9, 2023
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 9, 2023
  4. sjwang05 commented on Nov 10, 2023

    @sjwang05
    Contributor

    @rustbot claim

  5. added a commit that references this issue on Nov 13, 2023
    ea1e5cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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`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