Skip to content

Commit a35d7f2

Browse files
committed
Remove special case for statement NodeId assignment
We now let `noop_flat_map_stmt` assign `NodeId`s (via `visit_id`), just as we do for other AST nodes.
1 parent 1f94abc commit a35d7f2

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

compiler/rustc_expand/src/expand.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
559559
self.cx.force_mode = orig_force_mode;
560560

561561
// Finally incorporate all the expanded macros into the input AST fragment.
562-
let mut placeholder_expander = PlaceholderExpander::new(self.cx, self.monotonic);
562+
let mut placeholder_expander = PlaceholderExpander::default();
563563
while let Some(expanded_fragments) = expanded_fragments.pop() {
564564
for (expn_id, expanded_fragment) in expanded_fragments.into_iter().rev() {
565565
placeholder_expander
@@ -1341,14 +1341,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13411341
}
13421342
}
13431343

1344-
// The placeholder expander gives ids to statements, so we avoid folding the id here.
13451344
// We don't use `assign_id!` - it will be called when we visit statement's contents
13461345
// (e.g. an expression, item, or local)
1347-
let ast::Stmt { id, kind, span } = stmt;
1348-
let res = noop_flat_map_stmt_kind(kind, self)
1349-
.into_iter()
1350-
.map(|kind| ast::Stmt { id, kind, span })
1351-
.collect();
1346+
let res = noop_flat_map_stmt(stmt, self);
13521347

13531348
self.cx.current_expansion.is_trailing_mac = false;
13541349
res

compiler/rustc_expand/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(proc_macro_internals)]
88
#![feature(proc_macro_span)]
99
#![feature(try_blocks)]
10+
#![recursion_limit = "256"]
1011

1112
#[macro_use]
1213
extern crate rustc_macros;

compiler/rustc_expand/src/placeholders.rs

+4-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::base::ExtCtxt;
21
use crate::expand::{AstFragment, AstFragmentKind};
32

43
use rustc_ast as ast;
@@ -175,17 +174,12 @@ pub fn placeholder(
175174
}
176175
}
177176

178-
pub struct PlaceholderExpander<'a, 'b> {
177+
#[derive(Default)]
178+
pub struct PlaceholderExpander {
179179
expanded_fragments: FxHashMap<ast::NodeId, AstFragment>,
180-
cx: &'a mut ExtCtxt<'b>,
181-
monotonic: bool,
182180
}
183181

184-
impl<'a, 'b> PlaceholderExpander<'a, 'b> {
185-
pub fn new(cx: &'a mut ExtCtxt<'b>, monotonic: bool) -> Self {
186-
PlaceholderExpander { cx, expanded_fragments: FxHashMap::default(), monotonic }
187-
}
188-
182+
impl PlaceholderExpander {
189183
pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment) {
190184
fragment.mut_visit_with(self);
191185
self.expanded_fragments.insert(id, fragment);
@@ -196,7 +190,7 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> {
196190
}
197191
}
198192

199-
impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
193+
impl MutVisitor for PlaceholderExpander {
200194
fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {
201195
if arm.is_placeholder {
202196
self.remove(arm.id).make_arms()
@@ -360,15 +354,4 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
360354
_ => noop_visit_ty(ty, self),
361355
}
362356
}
363-
364-
fn visit_block(&mut self, block: &mut P<ast::Block>) {
365-
noop_visit_block(block, self);
366-
367-
for stmt in block.stmts.iter_mut() {
368-
if self.monotonic {
369-
assert_eq!(stmt.id, ast::DUMMY_NODE_ID);
370-
stmt.id = self.cx.resolver.next_node_id();
371-
}
372-
}
373-
}
374357
}

0 commit comments

Comments
 (0)