1
Fork 0

Macro call with braces does not require semicolon to be statement

This commit by itself is supposed to have no effect on behavior. All of
the call sites are updated to preserve their previous behavior.

The behavior changes are in the commits that follow.
This commit is contained in:
David Tolnay 2023-12-29 16:30:34 -08:00
parent cbb8714a3f
commit 9e1cf2098d
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
6 changed files with 50 additions and 23 deletions

View file

@ -498,7 +498,10 @@ impl<'a> Parser<'a> {
/// Checks if this expression is a successfully parsed statement.
fn expr_is_complete(&self, e: &Expr) -> bool {
self.restrictions.contains(Restrictions::STMT_EXPR)
&& !classify::expr_requires_semi_to_be_stmt_FIXME(e)
&& match e.kind {
ExprKind::MacCall(_) => false,
_ => !classify::expr_requires_semi_to_be_stmt(e),
}
}
/// Parses `x..y`, `x..=y`, and `x..`/`x..=`.
@ -2694,7 +2697,10 @@ impl<'a> Parser<'a> {
// If it's not a free-standing expression, and is followed by a block,
// then it's very likely the condition to an `else if`.
if self.check(&TokenKind::OpenDelim(Delimiter::Brace))
&& classify::expr_requires_semi_to_be_stmt_FIXME(&cond) =>
&& match cond.kind {
ExprKind::MacCall(_) => true,
_ => classify::expr_requires_semi_to_be_stmt(&cond),
} =>
{
self.dcx().emit_err(errors::ExpectedElseBlock {
first_tok_span,
@ -3136,8 +3142,10 @@ impl<'a> Parser<'a> {
err
})?;
let require_comma = classify::expr_requires_semi_to_be_stmt_FIXME(&expr)
&& this.token != token::CloseDelim(Delimiter::Brace);
let require_comma = match expr.kind {
ExprKind::MacCall(_) => true,
_ => classify::expr_requires_semi_to_be_stmt(&expr),
} && this.token != token::CloseDelim(Delimiter::Brace);
if !require_comma {
arm_body = Some(expr);

View file

@ -648,8 +648,10 @@ impl<'a> Parser<'a> {
match &mut stmt.kind {
// Expression without semicolon.
StmtKind::Expr(expr)
if classify::expr_requires_semi_to_be_stmt_FIXME(expr)
&& !expr.attrs.is_empty()
if match expr.kind {
ExprKind::MacCall(_) => true,
_ => classify::expr_requires_semi_to_be_stmt(expr),
} && !expr.attrs.is_empty()
&& ![token::Eof, token::Semi, token::CloseDelim(Delimiter::Brace)]
.contains(&self.token.kind) =>
{
@ -663,7 +665,10 @@ impl<'a> Parser<'a> {
// Expression without semicolon.
StmtKind::Expr(expr)
if self.token != token::Eof
&& classify::expr_requires_semi_to_be_stmt_FIXME(expr) =>
&& match expr.kind {
ExprKind::MacCall(_) => true,
_ => classify::expr_requires_semi_to_be_stmt(expr),
} =>
{
// Just check for errors and recover; do not eat semicolon yet.