Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let-chains parsing is not resilient to stray ; between lets #117720

Closed
estebank opened this issue Nov 8, 2023 · 1 comment · Fixed by #117743
Closed

let-chains parsing is not resilient to stray ; between lets #117720

estebank opened this issue Nov 8, 2023 · 1 comment · Fixed by #117743
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. F-let_chains `#![feature(let_chains)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Nov 8, 2023

Code

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

Current output

error: expected `{`, found `;`
 --> src/main.rs:4:23
  |
4 |         && let () = ();
  |                       ^ expected `{`
  |
note: the `if` expression is missing a block after this condition
 --> src/main.rs:3:8
  |
3 |       if let () = ()
  |  ________^
4 | |         && let () = ();
  | |______________________^

Desired output

error: expected `{`, found `;`
 --> src/main.rs:4:23
  |
4 |         && let () = ();
  |                       ^
  |                       |
  |                       expected `{`
  |                       help: remove it to parse the following `let` as part of the same chain
5 |         && let () = ()
  |         -------------- you likely meant to continue parsing the let-chain here

Rationale and extra context

This is a common typo I make when hoisting an inconditional let binding into the let chain to merge two let-chains that could be one. The parser only needs to do look-ahead 1 and 2 to detect the case and recover.

Other cases

No response

Anything else?

No response

@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-papercut Diagnostics: An error or lint that needs small tweaks. F-let_chains `#![feature(let_chains)]` labels Nov 8, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 8, 2023
@estebank estebank removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 8, 2023
@sjwang05
Copy link
Contributor

sjwang05 commented Nov 9, 2023

@rustbot claim

@bors bors closed this as completed in 7607597 Nov 10, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 10, 2023
Rollup merge of rust-lang#117743 - sjwang05:issue-117720, r=estebank

Suggest removing `;` for `;` within let-chains

Fixes rust-lang#117720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. F-let_chains `#![feature(let_chains)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants