Skip to content

Commit

Permalink
Normalize Stmt::Expr(Expr::Macro) to Stmt::Macro
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 29, 2024
1 parent cf9d796 commit a83b158
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/common/visit.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a83b158

Please sign in to comment.