diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-17 00:12:24 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-18 17:28:49 +1000 |
| commit | 487802d6c8a74ee375d2f71e3ff97cea11cc9c18 (patch) | |
| tree | 88b17695f452c3d186a87fca4682b4f44808261a /compiler/rustc_parse/src/parser/stmt.rs | |
| parent | 4bb2f278617e5498ac9a4776d3e1268154c500c5 (diff) | |
| download | rust-487802d6c8a74ee375d2f71e3ff97cea11cc9c18.tar.gz rust-487802d6c8a74ee375d2f71e3ff97cea11cc9c18.zip | |
Remove `TrailingToken`.
It's used in `Parser::collect_tokens_trailing_token` to decide whether to capture a trailing token. But the callers actually know whether to capture a trailing token, so it's simpler for them to just pass in a bool. Also, the `TrailingToken::Gt` case was weird, because it didn't result in a trailing token being captured. It could have been subsumed by the `TrailingToken::MaybeComma` case, and it effectively is in the new code.
Diffstat (limited to 'compiler/rustc_parse/src/parser/stmt.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index e7fcbf9c20f..3ec891b4eea 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -3,7 +3,6 @@ use super::diagnostics::AttemptLocalParseRecovery; use super::expr::LhsExpr; use super::pat::{PatternLocation, RecoverComma}; use super::path::PathStyle; -use super::TrailingToken; use super::{ AttrWrapper, BlockMode, FnParseMode, ForceCollect, Parser, Restrictions, SemiColonMode, }; @@ -149,11 +148,7 @@ impl<'a> Parser<'a> { if this.eat(&token::Not) { let stmt_mac = this.parse_stmt_mac(lo, attrs, path)?; - if this.token == token::Semi { - return Ok((stmt_mac, TrailingToken::Semi)); - } else { - return Ok((stmt_mac, TrailingToken::None)); - } + return Ok((stmt_mac, this.token == token::Semi)); } let expr = if this.eat(&token::OpenDelim(Delimiter::Brace)) { @@ -167,7 +162,7 @@ impl<'a> Parser<'a> { this.parse_expr_dot_or_call_with(attrs, expr, lo) })?; // `DUMMY_SP` will get overwritten later in this function - Ok((this.mk_stmt(rustc_span::DUMMY_SP, StmtKind::Expr(expr)), TrailingToken::None)) + Ok((this.mk_stmt(rustc_span::DUMMY_SP, StmtKind::Expr(expr)), false)) })?; if let StmtKind::Expr(expr) = stmt.kind { @@ -241,10 +236,7 @@ impl<'a> Parser<'a> { 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, - )) + 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) }); @@ -261,11 +253,7 @@ impl<'a> Parser<'a> { self.collect_tokens_trailing_token(attrs, force_collect, |this, attrs| { this.expect_keyword(kw::Let)?; let local = this.parse_local(attrs)?; - let trailing = if capture_semi && this.token.kind == token::Semi { - TrailingToken::Semi - } else { - TrailingToken::None - }; + let trailing = capture_semi && this.token.kind == token::Semi; Ok((this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Let(local)), trailing)) }) } |
