1
Fork 0

add derive macros' helper attributes to doc output

This commit is contained in:
QuietMisdreavus 2018-09-26 11:29:41 -05:00
parent 869ebc4f95
commit 27429d9415
5 changed files with 34 additions and 1 deletions

View 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,
})
}
}

View file

@ -3793,6 +3793,7 @@ impl Clean<Item> for doctree::Macro {
#[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 @@ impl Clean<Item> for doctree::ProcMacro {
def_id: cx.tcx.hir.local_def_id(self.id),
inner: ProcMacroItem(ProcMacro {
kind: self.kind,
helpers: self.helpers.clean(cx),
}),
}
}

View 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>,

View 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>")?;
}
_ => {}

View file

@ -197,10 +197,26 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
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),