about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRune Tynan <runetynan@gmail.com>2020-11-26 18:36:59 -0500
committerRune Tynan <runetynan@gmail.com>2020-11-27 21:58:54 -0500
commitccb9cc1200e26a5f0cdaac321bd10185d91e87e4 (patch)
tree01948c1294c4e5cb555aade5ed0edce8f38f5538
parentfd6b5376b723e22e3d98542e2e693d2717700900 (diff)
downloadrust-ccb9cc1200e26a5f0cdaac321bd10185d91e87e4.tar.gz
rust-ccb9cc1200e26a5f0cdaac321bd10185d91e87e4.zip
Remove doctree::Macro
-rw-r--r--src/librustdoc/clean/mod.rs21
-rw-r--r--src/librustdoc/doctree.rs11
-rw-r--r--src/librustdoc/visit_ast.rs21
3 files changed, 17 insertions, 36 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 03fda94a6df..f417eb6740c 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -2313,21 +2313,28 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Ident>) {
     }
 }
 
-impl Clean<Item> for doctree::Macro {
+impl Clean<Item> for (&hir::MacroDef<'_>, Option<Ident>) {
     fn clean(&self, cx: &DocContext<'_>) -> Item {
+        let (item, renamed) = self;
+        let name = renamed.unwrap_or(item.ident).name;
+        let tts = item.ast.body.inner_tokens().trees().collect::<Vec<_>>();
+        // Extract the spans of all matchers. They represent the "interface" of the macro.
+        let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect::<Vec<_>>();
+
         Item::from_def_id_and_parts(
-            self.def_id,
-            Some(self.name.clean(cx)),
+            cx.tcx.hir().local_def_id(item.hir_id).to_def_id(),
+            Some(name.clean(cx)),
             MacroItem(Macro {
+                // FIXME(#76761): Make this respect `macro_rules!` vs `pub macro`
                 source: format!(
                     "macro_rules! {} {{\n{}}}",
-                    self.name,
-                    self.matchers
+                    name,
+                    matchers
                         .iter()
                         .map(|span| { format!("    {} => {{ ... }};\n", span.to_src(cx)) })
-                        .collect::<String>()
+                        .collect::<String>(),
                 ),
-                imported_from: self.imported_from.clean(cx),
+                imported_from: None,
             }),
             cx,
         )
diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs
index 20f747e2014..3961870a1bf 100644
--- a/src/librustdoc/doctree.rs
+++ b/src/librustdoc/doctree.rs
@@ -18,7 +18,7 @@ crate struct Module<'hir> {
     // (item, renamed)
     crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
     crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
-    crate macros: Vec<Macro>,
+    crate macros: Vec<(&'hir hir::MacroDef<'hir>, Option<Ident>)>,
     crate is_crate: bool,
 }
 
@@ -56,15 +56,6 @@ crate struct Variant<'hir> {
     crate def: &'hir hir::VariantData<'hir>,
 }
 
-// For Macro we store the DefId instead of the NodeId, since we also create
-// these imported macro_rules (which only have a DUMMY_NODE_ID).
-crate struct Macro {
-    crate name: Symbol,
-    crate def_id: hir::def_id::DefId,
-    crate matchers: Vec<Span>,
-    crate imported_from: Option<Symbol>,
-}
-
 #[derive(Debug)]
 crate struct Import<'hir> {
     crate name: Symbol,
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs
index 02152edbbc2..4028293076d 100644
--- a/src/librustdoc/visit_ast.rs
+++ b/src/librustdoc/visit_ast.rs
@@ -71,9 +71,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
             None,
         );
         // Attach the crate's exported macros to the top-level module:
-        module
-            .macros
-            .extend(krate.exported_macros.iter().map(|def| self.visit_local_macro(def, None)));
+        module.macros.extend(krate.exported_macros.iter().map(|def| (def, None)));
         module.is_crate = true;
 
         self.cx.renderinfo.get_mut().exact_paths = self.exact_paths;
@@ -216,7 +214,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                 true
             }
             Node::MacroDef(def) if !glob => {
-                om.macros.push(self.visit_local_macro(def, renamed.map(|i| i.name)));
+                om.macros.push((def, renamed));
                 true
             }
             _ => false,
@@ -339,19 +337,4 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
             om.foreigns.push((item, renamed));
         }
     }
-
-    // Convert each `exported_macro` into a doc item.
-    fn visit_local_macro(&self, def: &'tcx hir::MacroDef<'_>, renamed: Option<Symbol>) -> Macro {
-        debug!("visit_local_macro: {}", def.ident);
-        let tts = def.ast.body.inner_tokens().trees().collect::<Vec<_>>();
-        // Extract the spans of all matchers. They represent the "interface" of the macro.
-        let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();
-
-        Macro {
-            def_id: self.cx.tcx.hir().local_def_id(def.hir_id).to_def_id(),
-            name: renamed.unwrap_or(def.ident.name),
-            matchers,
-            imported_from: None,
-        }
-    }
 }