diff --git a/tests/common/visit.rs b/tests/common/visit.rs index df2e150187..7330a5727e 100644 --- a/tests/common/visit.rs +++ b/tests/common/visit.rs @@ -1,6 +1,6 @@ use std::mem; use syn::visit_mut::{self, VisitMut}; -use syn::{Expr, File, Generics, LifetimeParam, TypeParam}; +use syn::{Expr, File, Generics, LifetimeParam, MacroDelimiter, Stmt, StmtMacro, TypeParam}; pub struct FlattenParens; @@ -41,6 +41,27 @@ impl VisitMut for AsIfPrinted { visit_mut::visit_lifetime_param_mut(self, param); } + fn visit_stmt_mut(&mut self, stmt: &mut Stmt) { + if let Stmt::Expr(expr, semi) = stmt { + if let Expr::Macro(e) = expr { + if match e.mac.delimiter { + MacroDelimiter::Brace(_) => true, + MacroDelimiter::Paren(_) | MacroDelimiter::Bracket(_) => semi.is_some(), + } { + let Expr::Macro(expr) = mem::replace(expr, Expr::PLACEHOLDER) else { + unreachable!(); + }; + *stmt = Stmt::Macro(StmtMacro { + attrs: expr.attrs, + mac: expr.mac, + semi_token: *semi, + }); + } + } + } + visit_mut::visit_stmt_mut(self, stmt); + } + fn visit_type_param_mut(&mut self, param: &mut TypeParam) { if param.bounds.is_empty() { param.colon_token = None;