diff options
| author | bors <bors@rust-lang.org> | 2023-11-15 06:49:27 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-15 06:49:27 +0000 |
| commit | 31e62a923d0e98d256a17112cd8668956033c2b5 (patch) | |
| tree | 78ac0a5038cf364e203c7e5719b4b07ff3cb34c5 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 177d8f2ee5f7c80347022ba3ba5b897630559572 (diff) | |
| parent | 34e83402b811b1c4994a68b3f72e60bff04bb076 (diff) | |
| download | rust-31e62a923d0e98d256a17112cd8668956033c2b5.tar.gz rust-31e62a923d0e98d256a17112cd8668956033c2b5.zip | |
Auto merge of #3165 - rust-lang:rustup-2023-11-15, r=RalfJung
Automatic Rustup
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 36125e138b2..235b28b6e26 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2303,13 +2303,14 @@ impl<'a> Parser<'a> { /// Parses an optional `move` prefix to a closure-like construct. fn parse_capture_clause(&mut self) -> PResult<'a, CaptureBy> { if self.eat_keyword(kw::Move) { + let move_kw_span = self.prev_token.span; // Check for `move async` and recover if self.check_keyword(kw::Async) { let move_async_span = self.token.span.with_lo(self.prev_token.span.data().lo); Err(errors::AsyncMoveOrderIncorrect { span: move_async_span } .into_diagnostic(&self.sess.span_diagnostic)) } else { - Ok(CaptureBy::Value) + Ok(CaptureBy::Value { move_kw: move_kw_span }) } } else { Ok(CaptureBy::Ref) @@ -2440,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 })? } |
