Skip to content

Commit 7d7e2a1

Browse files
committed
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.
1 parent e69ff1c commit 7d7e2a1

File tree

1 file changed

+9
-6
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+9
-6
lines changed

compiler/rustc_parse/src/parser/stmt.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,23 @@ impl<'a> Parser<'a> {
7272
lo,
7373
attrs,
7474
errors::InvalidVariableDeclarationSub::MissingLet,
75+
force_collect,
7576
)?
7677
} else if self.is_kw_followed_by_ident(kw::Auto) && self.may_recover() {
7778
self.bump(); // `auto`
7879
self.recover_stmt_local_after_let(
7980
lo,
8081
attrs,
8182
errors::InvalidVariableDeclarationSub::UseLetNotAuto,
83+
force_collect,
8284
)?
8385
} else if self.is_kw_followed_by_ident(sym::var) && self.may_recover() {
8486
self.bump(); // `var`
8587
self.recover_stmt_local_after_let(
8688
lo,
8789
attrs,
8890
errors::InvalidVariableDeclarationSub::UseLetNotVar,
91+
force_collect,
8992
)?
9093
} else if self.check_path()
9194
&& !self.token.is_qpath_start()
@@ -231,13 +234,13 @@ impl<'a> Parser<'a> {
231234
lo: Span,
232235
attrs: AttrWrapper,
233236
subdiagnostic: fn(Span) -> errors::InvalidVariableDeclarationSub,
237+
force_collect: ForceCollect,
234238
) -> PResult<'a, Stmt> {
235-
let stmt =
236-
self.collect_tokens_trailing_token(attrs, ForceCollect::Yes, |this, attrs| {
237-
let local = this.parse_local(attrs)?;
238-
// FIXME - maybe capture semicolon in recovery?
239-
Ok((this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Let(local)), false))
240-
})?;
239+
let stmt = self.collect_tokens_trailing_token(attrs, force_collect, |this, attrs| {
240+
let local = this.parse_local(attrs)?;
241+
// FIXME - maybe capture semicolon in recovery?
242+
Ok((this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Let(local)), false))
243+
})?;
241244
self.dcx()
242245
.emit_err(errors::InvalidVariableDeclaration { span: lo, sub: subdiagnostic(lo) });
243246
Ok(stmt)

0 commit comments

Comments
 (0)