]> git.lizzy.rs Git - rust.git/commitdiff
add derive macros' helper attributes to doc output
authorQuietMisdreavus <grey@quietmisdreavus.net>
Wed, 26 Sep 2018 16:29:41 +0000 (11:29 -0500)
committerQuietMisdreavus <grey@quietmisdreavus.net>
Wed, 26 Sep 2018 18:40:08 +0000 (13:40 -0500)
src/librustdoc/clean/inline.rs
src/librustdoc/clean/mod.rs
src/librustdoc/doctree.rs
src/librustdoc/html/render.rs
src/librustdoc/visit_ast.rs

index 4d1b6b8b1a98e1cb40e4ad2949a6b15b257f315a..a435712ac3d6ce75ae6f52e5995eb5c550d5bf7f 100644 (file)
@@ -13,7 +13,7 @@
 use std::iter::once;
 
 use syntax::ast;
-use syntax::ext::base::MacroKind;
+use syntax::ext::base::{MacroKind, SyntaxExtension};
 use syntax_pos::Span;
 
 use rustc::hir;
@@ -465,8 +465,14 @@ fn build_macro(cx: &DocContext, did: DefId, name: ast::Name) -> clean::ItemEnum
             })
         }
         LoadedMacro::ProcMacro(ext) => {
+            let helpers = match &*ext {
+                &SyntaxExtension::ProcMacroDerive(_, ref syms, ..) => { syms.clean(cx) }
+                _ => Vec::new(),
+            };
+
             clean::ProcMacroItem(clean::ProcMacro {
                 kind: ext.kind(),
+                helpers,
             })
         }
     }
index 244911150043c4682dd4a96d2d161504537fe765..41c4ee982ff79a1da107559239da00e0a4e426db 100644 (file)
@@ -3793,6 +3793,7 @@ fn clean(&self, cx: &DocContext) -> Item {
 #[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
 pub struct ProcMacro {
     pub kind: MacroKind,
+    pub helpers: Vec<String>,
 }
 
 impl Clean<Item> for doctree::ProcMacro {
@@ -3807,6 +3808,7 @@ fn clean(&self, cx: &DocContext) -> Item {
             def_id: cx.tcx.hir.local_def_id(self.id),
             inner: ProcMacroItem(ProcMacro {
                 kind: self.kind,
+                helpers: self.helpers.clean(cx),
             }),
         }
     }
index 538e61fcb4d32a1660cec6c8ad0a40bc4f724eb4..4a6a4ee09ea1a0276af9ad19b6e9c924c221edf0 100644 (file)
@@ -271,6 +271,7 @@ pub struct ProcMacro {
     pub name: Name,
     pub id: NodeId,
     pub kind: MacroKind,
+    pub helpers: Vec<Name>,
     pub attrs: hir::HirVec<ast::Attribute>,
     pub whence: Span,
     pub stab: Option<attr::Stability>,
index 107858ae60527c490f662bc6e6175cefca096dd1..998a48aca09fec79f6067f028f270ed6cb17dae8 100644 (file)
@@ -4626,6 +4626,14 @@ fn item_proc_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, m: &c
         MacroKind::Derive => {
             write!(w, "<pre class='rust derive'>")?;
             write!(w, "#[derive({})]", name)?;
+            if !m.helpers.is_empty() {
+                writeln!(w, "\n{{")?;
+                writeln!(w, "    // Attributes available to this derive:")?;
+                for attr in &m.helpers {
+                    writeln!(w, "    #[{}]", attr)?;
+                }
+                write!(w, "}}")?;
+            }
             write!(w, "</pre>")?;
         }
         _ => {}
index dbe25c5ff8a49f67426b35a51fc1fcdb9e5bd768..92d8dbed0718a5a1ecefde7e31024384de4b5188 100644 (file)
@@ -197,10 +197,26 @@ pub fn visit_fn(&mut self, om: &mut Module, item: &hir::Item,
                     name
                 };
 
+                let mut helpers = Vec::new();
+                for mi in item.attrs.lists("proc_macro_derive") {
+                    if !mi.check_name("attributes") {
+                        continue;
+                    }
+
+                    if let Some(list) = mi.meta_item_list() {
+                        for inner_mi in list {
+                            if let Some(name) = inner_mi.name() {
+                                helpers.push(name);
+                            }
+                        }
+                    }
+                }
+
                 om.proc_macros.push(ProcMacro {
                     name,
                     id: item.id,
                     kind,
+                    helpers,
                     attrs: item.attrs.clone(),
                     whence: item.span,
                     stab: self.stability(item.id),