Skip to content

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

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

Closed
estebank opened this issue Nov 9, 2023 · 1 comment · Fixed by #117770
Closed

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

estebank opened this issue Nov 9, 2023 · 1 comment · Fixed by #117770
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Nov 9, 2023

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

@estebank estebank added E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. labels Nov 9, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 9, 2023
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 9, 2023
@sjwang05
Copy link
Contributor

@rustbot claim

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 lexing & parsing of Rust source code to an AST A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-low Low priority 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.

4 participants