Skip to content

Commit e3d9f19

Browse files
rustdoc: hide macro export statements from docs
1 parent 90463a6 commit e3d9f19

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/librustdoc/clean/inline.rs

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa
9797
record_extern_fqn(cx, did, clean::TypeKind::Const);
9898
clean::ConstantItem(build_const(cx, did))
9999
}
100+
// Macros are eagerly inlined back in visit_ast, don't show their export statements
101+
// FIXME(50647): the eager inline does not take doc(hidden)/doc(no_inline) into account
102+
Def::Macro(..) => return Some(Vec::new()),
100103
_ => return None,
101104
};
102105
cx.renderinfo.borrow_mut().inlined.insert(did);

src/librustdoc/visit_ast.rs

+4
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
219219
if let Some(exports) = self.cx.tcx.module_exports(def_id) {
220220
for export in exports.iter().filter(|e| e.vis == Visibility::Public) {
221221
if let Def::Macro(def_id, ..) = export.def {
222+
// FIXME(50647): this eager macro inlining does not take
223+
// doc(hidden)/doc(no_inline) into account
222224
if def_id.krate == LOCAL_CRATE {
223225
continue // These are `krate.exported_macros`, handled in `self.visit()`.
224226
}
@@ -237,6 +239,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
237239
unreachable!()
238240
};
239241

242+
debug!("inlining macro {}", def.ident.name);
240243
om.macros.push(Macro {
241244
def_id,
242245
attrs: def.attrs.clone().into(),
@@ -561,6 +564,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
561564

562565
// convert each exported_macro into a doc item
563566
fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro {
567+
debug!("visit_local_macro: {}", def.name);
564568
let tts = def.body.trees().collect::<Vec<_>>();
565569
// Extract the spans of all matchers. They represent the "interface" of the macro.
566570
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();

0 commit comments

Comments
 (0)