Skip to content

Commit 27429d9

Browse files
add derive macros' helper attributes to doc output
1 parent 869ebc4 commit 27429d9

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

Diff for: src/librustdoc/clean/inline.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use std::iter::once;
1414

1515
use syntax::ast;
16-
use syntax::ext::base::MacroKind;
16+
use syntax::ext::base::{MacroKind, SyntaxExtension};
1717
use syntax_pos::Span;
1818

1919
use rustc::hir;
@@ -465,8 +465,14 @@ fn build_macro(cx: &DocContext, did: DefId, name: ast::Name) -> clean::ItemEnum
465465
})
466466
}
467467
LoadedMacro::ProcMacro(ext) => {
468+
let helpers = match &*ext {
469+
&SyntaxExtension::ProcMacroDerive(_, ref syms, ..) => { syms.clean(cx) }
470+
_ => Vec::new(),
471+
};
472+
468473
clean::ProcMacroItem(clean::ProcMacro {
469474
kind: ext.kind(),
475+
helpers,
470476
})
471477
}
472478
}

Diff for: src/librustdoc/clean/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3793,6 +3793,7 @@ impl Clean<Item> for doctree::Macro {
37933793
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
37943794
pub struct ProcMacro {
37953795
pub kind: MacroKind,
3796+
pub helpers: Vec<String>,
37963797
}
37973798

37983799
impl Clean<Item> for doctree::ProcMacro {
@@ -3807,6 +3808,7 @@ impl Clean<Item> for doctree::ProcMacro {
38073808
def_id: cx.tcx.hir.local_def_id(self.id),
38083809
inner: ProcMacroItem(ProcMacro {
38093810
kind: self.kind,
3811+
helpers: self.helpers.clean(cx),
38103812
}),
38113813
}
38123814
}

Diff for: src/librustdoc/doctree.rs

+1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ pub struct ProcMacro {
271271
pub name: Name,
272272
pub id: NodeId,
273273
pub kind: MacroKind,
274+
pub helpers: Vec<Name>,
274275
pub attrs: hir::HirVec<ast::Attribute>,
275276
pub whence: Span,
276277
pub stab: Option<attr::Stability>,

Diff for: src/librustdoc/html/render.rs

+8
Original file line numberDiff line numberDiff line change
@@ -4626,6 +4626,14 @@ fn item_proc_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, m: &c
46264626
MacroKind::Derive => {
46274627
write!(w, "<pre class='rust derive'>")?;
46284628
write!(w, "#[derive({})]", name)?;
4629+
if !m.helpers.is_empty() {
4630+
writeln!(w, "\n{{")?;
4631+
writeln!(w, " // Attributes available to this derive:")?;
4632+
for attr in &m.helpers {
4633+
writeln!(w, " #[{}]", attr)?;
4634+
}
4635+
write!(w, "}}")?;
4636+
}
46294637
write!(w, "</pre>")?;
46304638
}
46314639
_ => {}

Diff for: src/librustdoc/visit_ast.rs

+16
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,26 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
197197
name
198198
};
199199

200+
let mut helpers = Vec::new();
201+
for mi in item.attrs.lists("proc_macro_derive") {
202+
if !mi.check_name("attributes") {
203+
continue;
204+
}
205+
206+
if let Some(list) = mi.meta_item_list() {
207+
for inner_mi in list {
208+
if let Some(name) = inner_mi.name() {
209+
helpers.push(name);
210+
}
211+
}
212+
}
213+
}
214+
200215
om.proc_macros.push(ProcMacro {
201216
name,
202217
id: item.id,
203218
kind,
219+
helpers,
204220
attrs: item.attrs.clone(),
205221
whence: item.span,
206222
stab: self.stability(item.id),

0 commit comments

Comments
 (0)