Skip to content

Commit 48ac127

Browse files
committed
Remove MacCall special cases from Parser::parse_full_stmt
It is impossible for expr here to be a braced macro call. Expr comes from `parse_stmt_without_recovery`, in which macro calls are parsed by `parse_stmt_mac`. See this part: let kind = if (style == MacStmtStyle::Braces && self.token != token::Dot && self.token != token::Question) || self.token == token::Semi || self.token == token::Eof { StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None })) } else { // Since none of the above applied, this is an expression statement macro. let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac)); let e = self.maybe_recover_from_bad_qpath(e)?; let e = self.parse_expr_dot_or_call_with(e, lo, attrs)?; let e = self.parse_expr_assoc_with( 0, LhsExpr::AlreadyParsed { expr: e, starts_statement: false }, )?; StmtKind::Expr(e) }; A braced macro call at the head of a statement is always either extended into ExprKind::Field / MethodCall / Await / Try / Binary, or else returned as StmtKind::MacCall. We can never get a StmtKind::Expr containing ExprKind::MacCall containing brace delimiter.
1 parent 412e7a9 commit 48ac127

File tree

1 file changed

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

1 file changed

+3
-9
lines changed

compiler/rustc_parse/src/parser/stmt.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,8 @@ impl<'a> Parser<'a> {
637637
match &mut stmt.kind {
638638
// Expression without semicolon.
639639
StmtKind::Expr(expr)
640-
if match expr.kind {
641-
ExprKind::MacCall(_) => true,
642-
_ => classify::expr_requires_semi_to_be_stmt(expr),
643-
} && !expr.attrs.is_empty()
640+
if classify::expr_requires_semi_to_be_stmt(expr)
641+
&& !expr.attrs.is_empty()
644642
&& ![token::Eof, token::Semi, token::CloseDelim(Delimiter::Brace)]
645643
.contains(&self.token.kind) =>
646644
{
@@ -653,11 +651,7 @@ impl<'a> Parser<'a> {
653651

654652
// Expression without semicolon.
655653
StmtKind::Expr(expr)
656-
if self.token != token::Eof
657-
&& match expr.kind {
658-
ExprKind::MacCall(_) => true,
659-
_ => classify::expr_requires_semi_to_be_stmt(expr),
660-
} =>
654+
if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) =>
661655
{
662656
// Just check for errors and recover; do not eat semicolon yet.
663657
// `expect_one_of` returns PResult<'a, bool /* recovered */>

0 commit comments

Comments
 (0)