Skip to content

Commit 5a8bbf1

Browse files
committed
Fixes #32922, a macro hygiene bug
1 parent 23a7d30 commit 5a8bbf1

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,13 @@ pub fn expand_item_mac(it: P<ast::Item>,
504504

505505
/// Expand a stmt
506506
fn expand_stmt(stmt: Stmt, fld: &mut MacroExpander) -> SmallVector<Stmt> {
507+
// perform all pending renames
508+
let stmt = {
509+
let pending_renames = &mut fld.cx.syntax_env.info().pending_renames;
510+
let mut rename_fld = IdentRenamer{renames:pending_renames};
511+
rename_fld.fold_stmt(stmt).expect_one("rename_fold didn't return one value")
512+
};
513+
507514
let (mac, style, attrs) = match stmt.node {
508515
StmtKind::Mac(mac, style, attrs) => (mac, style, attrs),
509516
_ => return expand_non_macro_stmt(stmt, fld)
@@ -717,14 +724,8 @@ pub fn expand_block(blk: P<Block>, fld: &mut MacroExpander) -> P<Block> {
717724
pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> {
718725
b.map(|Block {id, stmts, expr, rules, span}| {
719726
let new_stmts = stmts.into_iter().flat_map(|x| {
720-
// perform all pending renames
721-
let renamed_stmt = {
722-
let pending_renames = &mut fld.cx.syntax_env.info().pending_renames;
723-
let mut rename_fld = IdentRenamer{renames:pending_renames};
724-
rename_fld.fold_stmt(x).expect_one("rename_fold didn't return one value")
725-
};
726-
// expand macros in the statement
727-
fld.fold_stmt(renamed_stmt).into_iter()
727+
// perform pending renames and expand macros in the statement
728+
fld.fold_stmt(x).into_iter()
728729
}).collect();
729730
let new_expr = expr.map(|x| {
730731
let expr = {

0 commit comments

Comments
 (0)