Skip to content

Commit cfc3fee

Browse files
committed
Revert "Rollup merge of rust-lang#87779 - Aaron1011:stmt-ast-id, r=petrochenkov"
Fixes rust-lang#87877 This change interacts badly with `noop_flat_map_stmt`, which synthesizes multiple statements with the same `NodeId`. I'm working on a better fix that will still allow us to remove this special case. For now, let's revert the change to fix the ICE. This reverts commit a4262cc, reversing changes made to 8ee962f.
1 parent 4e90017 commit cfc3fee

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

compiler/rustc_expand/src/expand.rs

+7-2
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::default();
562+
let mut placeholder_expander = PlaceholderExpander::new(self.cx, self.monotonic);
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,9 +1341,14 @@ 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.
13441345
// We don't use `assign_id!` - it will be called when we visit statement's contents
13451346
// (e.g. an expression, item, or local)
1346-
let res = noop_flat_map_stmt(stmt, self);
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();
13471352

13481353
self.cx.current_expansion.is_trailing_mac = false;
13491354
res

compiler/rustc_expand/src/lib.rs

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

1211
#[macro_use]
1312
extern crate rustc_macros;

compiler/rustc_expand/src/placeholders.rs

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

34
use rustc_ast as ast;
@@ -174,12 +175,17 @@ pub fn placeholder(
174175
}
175176
}
176177

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

182-
impl PlaceholderExpander {
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+
183189
pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment) {
184190
fragment.mut_visit_with(self);
185191
self.expanded_fragments.insert(id, fragment);
@@ -190,7 +196,7 @@ impl PlaceholderExpander {
190196
}
191197
}
192198

193-
impl MutVisitor for PlaceholderExpander {
199+
impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
194200
fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {
195201
if arm.is_placeholder {
196202
self.remove(arm.id).make_arms()
@@ -354,4 +360,15 @@ impl MutVisitor for PlaceholderExpander {
354360
_ => noop_visit_ty(ty, self),
355361
}
356362
}
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+
}
357374
}

0 commit comments

Comments
 (0)