about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-11-10 02:18:27 +0000
committerbors <bors@rust-lang.org>2023-11-10 02:18:27 +0000
commitd42d73b144fbb6ccc9684b197a3b6ed53592d09b (patch)
tree4007b538added9740bd0dd7a71d450d45396fc72 /compiler/rustc_parse/src/parser
parent0f44eb32f1123ac93ab404d74c295263ce468343 (diff)
parent186a3c8c61c02d10179b3df9c6386855a278efe4 (diff)
downloadrust-d42d73b144fbb6ccc9684b197a3b6ed53592d09b.tar.gz
rust-d42d73b144fbb6ccc9684b197a3b6ed53592d09b.zip
Auto merge of #117769 - matthiaskrgr:rollup-4efjlg3, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #114191 (Update exploit mitigations documentation)
 - #117039 (Clarify UB in `get_unchecked(_mut)`)
 - #117730 (Closure-consuming helper functions for `fmt::Debug` helpers)
 - #117741 (Fix typo in internal.rs)
 - #117743 (Suggest removing `;` for `;` within let-chains)
 - #117751 (rustdoc-json: Fix test so it actually checks things)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-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
                     })?
                 }