diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-17 02:27:01 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-19 08:24:53 +1000 |
| commit | 7d7e2a173aac29bd89435096347613f445a5202f (patch) | |
| tree | 34f9358f1b4d8930abd7aaffc4e86a6e89d1535c /compiler/rustc_parse/src/parser/stmt.rs | |
| parent | e69ff1c1065933b3737e662f8f237ffbee964755 (diff) | |
| download | rust-7d7e2a173aac29bd89435096347613f445a5202f.tar.gz rust-7d7e2a173aac29bd89435096347613f445a5202f.zip | |
Don't always force collect tokens in `recover_stmt_local_after_let`.
Use a parameter to decide whether to force collect, as is done for the closely related `parse_local_mk` method.
Diffstat (limited to 'compiler/rustc_parse/src/parser/stmt.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 3ec891b4eea..69dd3a3d65a 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -72,6 +72,7 @@ impl<'a> Parser<'a> { lo, attrs, errors::InvalidVariableDeclarationSub::MissingLet, + force_collect, )? } else if self.is_kw_followed_by_ident(kw::Auto) && self.may_recover() { self.bump(); // `auto` @@ -79,6 +80,7 @@ impl<'a> Parser<'a> { lo, attrs, errors::InvalidVariableDeclarationSub::UseLetNotAuto, + force_collect, )? } else if self.is_kw_followed_by_ident(sym::var) && self.may_recover() { self.bump(); // `var` @@ -86,6 +88,7 @@ impl<'a> Parser<'a> { lo, attrs, errors::InvalidVariableDeclarationSub::UseLetNotVar, + force_collect, )? } else if self.check_path() && !self.token.is_qpath_start() @@ -231,13 +234,13 @@ impl<'a> Parser<'a> { lo: Span, attrs: AttrWrapper, subdiagnostic: fn(Span) -> errors::InvalidVariableDeclarationSub, + force_collect: ForceCollect, ) -> PResult<'a, Stmt> { - let stmt = - self.collect_tokens_trailing_token(attrs, ForceCollect::Yes, |this, attrs| { - let local = this.parse_local(attrs)?; - // FIXME - maybe capture semicolon in recovery? - Ok((this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Let(local)), false)) - })?; + let stmt = self.collect_tokens_trailing_token(attrs, force_collect, |this, attrs| { + let local = this.parse_local(attrs)?; + // FIXME - maybe capture semicolon in recovery? + Ok((this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Let(local)), false)) + })?; self.dcx() .emit_err(errors::InvalidVariableDeclaration { span: lo, sub: subdiagnostic(lo) }); Ok(stmt) |
