about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-11-10 01:50:25 +0100
committerGitHub <noreply@github.com>2023-11-10 01:50:25 +0100
commit7607597d3affe175ed8fca1df5582f3078b57d94 (patch)
treef362e612995314661c55d5bc2caceae21399c52f /compiler
parent7fd7719ca158589fa795678826cbf5991599f612 (diff)
parent5693a34db2f0e929995fe7aa03d307bafa9360aa (diff)
downloadrust-7607597d3affe175ed8fca1df5582f3078b57d94.tar.gz
rust-7607597d3affe175ed8fca1df5582f3078b57d94.zip
Rollup merge of #117743 - sjwang05:issue-117720, r=estebank
Suggest removing `;` for `;` within let-chains

Fixes #117720
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 19690a6964b..235b28b6e26 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -2441,10 +2441,26 @@ impl<'a> Parser<'a> {
                     self.error_on_extra_if(&cond)?;
                     // Parse block, which will always fail, but we can add a nice note to the error
                     self.parse_block().map_err(|mut err| {
-                        err.span_note(
-                            cond_span,
-                            "the `if` expression is missing a block after this condition",
-                        );
+                        if self.prev_token == token::Semi
+                            && self.token == token::AndAnd
+                            && let maybe_let = self.look_ahead(1, |t| t.clone())
+                            && maybe_let.is_keyword(kw::Let)
+                        {
+                            err.span_suggestion(
+                                self.prev_token.span,
+                                "consider removing this semicolon to parse the `let` as part of the same chain",
+                                "",
+                                Applicability::MachineApplicable,
+                            ).span_note(
+                                self.token.span.to(maybe_let.span),
+                                "you likely meant to continue parsing the let-chain starting here",
+                            );
+                        } else {
+                            err.span_note(
+                                cond_span,
+                                "the `if` expression is missing a block after this condition",
+                            );
+                        }
                         err
                     })?
                 }