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;
})
}
LoadedMacro::ProcMacro(ext) => {
+ let helpers = match &*ext {
+ &SyntaxExtension::ProcMacroDerive(_, ref syms, ..) => { syms.clean(cx) }
+ _ => Vec::new(),
+ };
+
clean::ProcMacroItem(clean::ProcMacro {
kind: ext.kind(),
+ helpers,
})
}
}
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct ProcMacro {
pub kind: MacroKind,
+ pub helpers: Vec<String>,
}
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),
}),
}
}
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>,
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>")?;
}
_ => {}
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),