From 6dcc48070fe72764d1d708db5c16c9e77dc8eeb9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 22 Mar 2023 13:20:15 -0700 Subject: [PATCH] Keep non-brace macro invocations in trailing expr position as Expr::Macro --- src/stmt.rs | 7 +++++-- tests/test_stmt.rs | 25 ++++++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/stmt.rs b/src/stmt.rs index 55b9c8bc8a..f0dd7f6951 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -371,14 +371,17 @@ pub(crate) mod parsing { let semi_token: Option = input.parse()?; - if allow_nosemi.0 || semi_token.is_some() { - if let Expr::Macro(ExprMacro { attrs, mac }) = e { + match e { + Expr::Macro(ExprMacro { attrs, mac }) + if semi_token.is_some() || mac.delimiter.is_brace() => + { return Ok(Stmt::Macro(StmtMacro { attrs, mac, semi_token, })); } + _ => {} } if semi_token.is_some() { diff --git a/tests/test_stmt.rs b/tests/test_stmt.rs index 73574a84d3..bc57685df7 100644 --- a/tests/test_stmt.rs +++ b/tests/test_stmt.rs @@ -213,19 +213,22 @@ fn test_macros() { }, semi_token: Some, }, - Stmt::Macro { - mac: Macro { - path: Path { - segments: [ - PathSegment { - ident: "vec", - }, - ], + Stmt::Expr( + Expr::Macro { + mac: Macro { + path: Path { + segments: [ + PathSegment { + ident: "vec", + }, + ], + }, + delimiter: MacroDelimiter::Bracket, + tokens: TokenStream(``), }, - delimiter: MacroDelimiter::Bracket, - tokens: TokenStream(``), }, - }, + None, + ), ], }, })