Skip to content

Commit f3c7333

Browse files
committed
Cleanup depths.
1 parent 21b4369 commit f3c7333

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
224224
let (expansion, mut invocations) = self.collect_invocations(expansion);
225225
invocations.reverse();
226226

227-
let mut expansions = vec![vec![(0, expansion)]];
227+
let mut expansions = Vec::new();
228228
while let Some(invoc) = invocations.pop() {
229229
let ExpansionData { depth, mark, .. } = invoc.expansion_data;
230230
self.cx.current_expansion = invoc.expansion_data.clone();
@@ -236,13 +236,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
236236
None => invoc.expansion_kind.dummy(invoc.span()),
237237
};
238238

239-
self.cx.current_expansion.depth = depth + 1;
240239
let (expansion, new_invocations) = self.collect_invocations(expansion);
241240

242-
if expansions.len() == depth {
241+
if expansions.len() < depth {
243242
expansions.push(Vec::new());
244243
}
245-
expansions[depth].push((mark.as_u32(), expansion));
244+
expansions[depth - 1].push((mark.as_u32(), expansion));
246245
if !self.cx.ecfg.single_step {
247246
invocations.extend(new_invocations.into_iter().rev());
248247
}
@@ -253,12 +252,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
253252
let mut placeholder_expander = PlaceholderExpander::new(self.cx, self.monotonic);
254253
while let Some(expansions) = expansions.pop() {
255254
for (mark, expansion) in expansions.into_iter().rev() {
256-
let expansion = expansion.fold_with(&mut placeholder_expander);
257255
placeholder_expander.add(ast::NodeId::from_u32(mark), expansion);
258256
}
259257
}
260258

261-
placeholder_expander.remove(ast::NodeId::from_u32(0))
259+
expansion.fold_with(&mut placeholder_expander)
262260
}
263261

264262
fn collect_invocations(&mut self, expansion: Expansion) -> (Expansion, Vec<Invocation>) {
@@ -541,7 +539,11 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
541539
self.invocations.push(Invocation {
542540
kind: kind,
543541
expansion_kind: expansion_kind,
544-
expansion_data: ExpansionData { mark: mark, ..self.cx.current_expansion.clone() },
542+
expansion_data: ExpansionData {
543+
mark: mark,
544+
depth: self.cx.current_expansion.depth + 1,
545+
..self.cx.current_expansion.clone()
546+
},
545547
});
546548
placeholder(expansion_kind, ast::NodeId::from_u32(mark.as_u32()))
547549
}

src/libsyntax/ext/placeholders.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> {
8888
}
8989

9090
pub fn add(&mut self, id: ast::NodeId, expansion: Expansion) {
91+
let expansion = expansion.fold_with(self);
9192
self.expansions.insert(id, expansion);
9293
}
9394

94-
pub fn remove(&mut self, id: ast::NodeId) -> Expansion {
95+
fn remove(&mut self, id: ast::NodeId) -> Expansion {
9596
self.expansions.remove(&id).unwrap()
9697
}
9798
}

0 commit comments

Comments
 (0)