Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: hide macro export statements from docs #51011

Merged
merged 3 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa
record_extern_fqn(cx, did, clean::TypeKind::Const);
clean::ConstantItem(build_const(cx, did))
}
// Macros are eagerly inlined back in visit_ast, don't show their export statements
// FIXME(50647): the eager inline does not take doc(hidden)/doc(no_inline) into account
Def::Macro(..) => return Some(Vec::new()),
_ => return None,
};
cx.renderinfo.borrow_mut().inlined.insert(did);
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
if let Some(exports) = self.cx.tcx.module_exports(def_id) {
for export in exports.iter().filter(|e| e.vis == Visibility::Public) {
if let Def::Macro(def_id, ..) = export.def {
// FIXME(50647): this eager macro inlining does not take
// doc(hidden)/doc(no_inline) into account
if def_id.krate == LOCAL_CRATE {
continue // These are `krate.exported_macros`, handled in `self.visit()`.
}
Expand All @@ -237,6 +239,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
unreachable!()
};

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

// convert each exported_macro into a doc item
fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro {
debug!("visit_local_macro: {}", def.name);
let tts = def.body.trees().collect::<Vec<_>>();
// Extract the spans of all matchers. They represent the "interface" of the macro.
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();
Expand Down
1 change: 1 addition & 0 deletions src/test/rustdoc/pub-use-extern-macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
extern crate macros;

// @has pub_use_extern_macros/macro.bar.html
// @!has pub_use_extern_macros/index.html 'pub use macros::bar;'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be something like // @!has pub_use_extern_macros/index.html '//code' 'pub use macros::bar;' to actually test this. The other @!has tests in this file need to be fixed in the same way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's a good point! It looks like the 2-operator @has command doesn't do any HTML parsing. I didn't realize that. >_>

pub use macros::bar;

// @has pub_use_extern_macros/macro.baz.html
Expand Down