Skip to content

Commit

Permalink
Don't always force collect tokens in recover_stmt_local_after_let.
Browse files Browse the repository at this point in the history
Use a parameter to decide whether to force collect, as is done for the
closely related `parse_local_mk` method.
  • Loading branch information
nnethercote committed Jul 18, 2024
1 parent 4e98ea3 commit 54e5128
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions compiler/rustc_parse/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,23 @@ 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`
self.recover_stmt_local_after_let(
lo,
attrs,
errors::InvalidVariableDeclarationSub::UseLetNotAuto,
force_collect,
)?
} else if self.is_kw_followed_by_ident(sym::var) && self.may_recover() {
self.bump(); // `var`
self.recover_stmt_local_after_let(
lo,
attrs,
errors::InvalidVariableDeclarationSub::UseLetNotVar,
force_collect,
)?
} else if self.check_path()
&& !self.token.is_qpath_start()
Expand Down Expand Up @@ -236,16 +239,16 @@ 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)),
TrailingToken::None,
))
})?;
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)),
TrailingToken::None,
))
})?;
self.dcx()
.emit_err(errors::InvalidVariableDeclaration { span: lo, sub: subdiagnostic(lo) });
Ok(stmt)
Expand Down

0 comments on commit 54e5128

Please sign in to comment.