Skip to content

Commit

Permalink
Merge pull request #1420 from dtolnay/nonbracemacro
Browse files Browse the repository at this point in the history
Keep non-brace macro invocations in trailing expr position as Expr::Macro
  • Loading branch information
dtolnay authored Mar 22, 2023
2 parents d12db40 + 6dcc480 commit e76d644
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,17 @@ pub(crate) mod parsing {

let semi_token: Option<Token![;]> = 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() {
Expand Down
25 changes: 14 additions & 11 deletions tests/test_stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
],
},
})
Expand Down

0 comments on commit e76d644

Please sign in to comment.