X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_expand%2Fsrc%2Fplaceholders.rs;h=6586ba138fb9956c61baf25f0eb13edd301cdbd5;hb=5a19ffe1c2b99d9e09706cc286aad1ec0868eddb;hp=8e78fcbb8dbc14a40110def4bda0c03506a63947;hpb=47b41b7788a6f85c749049062f1e4eed497cd894;p=rust.git diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 8e78fcbb8db..6586ba138fb 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -1,3 +1,4 @@ +use crate::base::ExtCtxt; use crate::expand::{AstFragment, AstFragmentKind}; use rustc_ast as ast; @@ -174,12 +175,17 @@ fn mac_placeholder() -> ast::MacCall { } } -#[derive(Default)] -pub struct PlaceholderExpander { +pub struct PlaceholderExpander<'a, 'b> { expanded_fragments: FxHashMap, + cx: &'a mut ExtCtxt<'b>, + monotonic: bool, } -impl PlaceholderExpander { +impl<'a, 'b> PlaceholderExpander<'a, 'b> { + pub fn new(cx: &'a mut ExtCtxt<'b>, monotonic: bool) -> Self { + PlaceholderExpander { cx, expanded_fragments: FxHashMap::default(), monotonic } + } + pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment) { fragment.mut_visit_with(self); self.expanded_fragments.insert(id, fragment); @@ -190,7 +196,7 @@ fn remove(&mut self, id: ast::NodeId) -> AstFragment { } } -impl MutVisitor for PlaceholderExpander { +impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> { fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> { if arm.is_placeholder { self.remove(arm.id).make_arms() @@ -354,4 +360,15 @@ fn visit_ty(&mut self, ty: &mut P) { _ => noop_visit_ty(ty, self), } } + + fn visit_block(&mut self, block: &mut P) { + noop_visit_block(block, self); + + for stmt in block.stmts.iter_mut() { + if self.monotonic { + assert_eq!(stmt.id, ast::DUMMY_NODE_ID); + stmt.id = self.cx.resolver.next_node_id(); + } + } + } }