about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2021-08-12 08:23:56 -0500
committerAaron Hill <aa1ronham@gmail.com>2021-08-12 08:24:22 -0500
commitcfc3fee952589dc5140a25dfe28b07f5d4fd7aa0 (patch)
tree3bca1f7dc6e31e1cd8426c1dc57632e870dea331 /compiler/rustc_expand/src
parent4e900176b6c402035a6e52da03d453c848f0b336 (diff)
downloadrust-cfc3fee952589dc5140a25dfe28b07f5d4fd7aa0.tar.gz
rust-cfc3fee952589dc5140a25dfe28b07f5d4fd7aa0.zip
Revert "Rollup merge of #87779 - Aaron1011:stmt-ast-id, r=petrochenkov"
Fixes #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 a4262cc9841d91d48ef994b36eab323e615a7083, reversing
changes made to 8ee962f88e1be7e29482b13c7776c26b98a93bf7.
Diffstat (limited to 'compiler/rustc_expand/src')
-rw-r--r--compiler/rustc_expand/src/expand.rs9
-rw-r--r--compiler/rustc_expand/src/lib.rs1
-rw-r--r--compiler/rustc_expand/src/placeholders.rs25
3 files changed, 28 insertions, 7 deletions
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs
index 3629e668fa9..09beda33483 100644
--- a/compiler/rustc_expand/src/expand.rs
+++ b/compiler/rustc_expand/src/expand.rs
@@ -559,7 +559,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
         self.cx.force_mode = orig_force_mode;
 
         // Finally incorporate all the expanded macros into the input AST fragment.
-        let mut placeholder_expander = PlaceholderExpander::default();
+        let mut placeholder_expander = PlaceholderExpander::new(self.cx, self.monotonic);
         while let Some(expanded_fragments) = expanded_fragments.pop() {
             for (expn_id, expanded_fragment) in expanded_fragments.into_iter().rev() {
                 placeholder_expander
@@ -1341,9 +1341,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
             }
         }
 
+        // The placeholder expander gives ids to statements, so we avoid folding the id here.
         // We don't use `assign_id!` - it will be called when we visit statement's contents
         // (e.g. an expression, item, or local)
-        let res = noop_flat_map_stmt(stmt, self);
+        let ast::Stmt { id, kind, span } = stmt;
+        let res = noop_flat_map_stmt_kind(kind, self)
+            .into_iter()
+            .map(|kind| ast::Stmt { id, kind, span })
+            .collect();
 
         self.cx.current_expansion.is_trailing_mac = false;
         res
diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs
index 43287984050..efed41de23a 100644
--- a/compiler/rustc_expand/src/lib.rs
+++ b/compiler/rustc_expand/src/lib.rs
@@ -7,7 +7,6 @@
 #![feature(proc_macro_internals)]
 #![feature(proc_macro_span)]
 #![feature(try_blocks)]
-#![recursion_limit = "256"]
 
 #[macro_use]
 extern crate rustc_macros;
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 @@ pub fn placeholder(
     }
 }
 
-#[derive(Default)]
-pub struct PlaceholderExpander {
+pub struct PlaceholderExpander<'a, 'b> {
     expanded_fragments: FxHashMap<ast::NodeId, AstFragment>,
+    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 @@ impl PlaceholderExpander {
     }
 }
 
-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 @@ impl MutVisitor for PlaceholderExpander {
             _ => noop_visit_ty(ty, self),
         }
     }
+
+    fn visit_block(&mut self, block: &mut P<ast::Block>) {
+        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();
+            }
+        }
+    }
 }