From e3d9f1921973ee260753a0fb434c70185d2d96db Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Wed, 23 May 2018 16:22:18 -0500 Subject: [PATCH 1/3] rustdoc: hide macro export statements from docs --- src/librustdoc/clean/inline.rs | 3 +++ src/librustdoc/visit_ast.rs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index a8f4848bf89f2..782c8bf6dd177 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -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); diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 6db02cc6cc105..8c2555c4b3de2 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -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()`. } @@ -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(), @@ -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::>(); // Extract the spans of all matchers. They represent the "interface" of the macro. let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect(); From d19b5edfb0bde5bc2929668eeacb543c02f66bb7 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Wed, 23 May 2018 16:39:47 -0500 Subject: [PATCH 2/3] update "pub-use-extern-macros" test to hide the regular import statement --- src/test/rustdoc/pub-use-extern-macros.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/rustdoc/pub-use-extern-macros.rs b/src/test/rustdoc/pub-use-extern-macros.rs index 57d54585d84bc..2c1f2bf0be4f4 100644 --- a/src/test/rustdoc/pub-use-extern-macros.rs +++ b/src/test/rustdoc/pub-use-extern-macros.rs @@ -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;' pub use macros::bar; // @has pub_use_extern_macros/macro.baz.html From 4cf0c5fa329011b5e8059185d00dc069616c8979 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Wed, 23 May 2018 20:53:45 -0500 Subject: [PATCH 3/3] fix @!has conditions in pub-use-extern-macros test --- src/test/rustdoc/pub-use-extern-macros.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/rustdoc/pub-use-extern-macros.rs b/src/test/rustdoc/pub-use-extern-macros.rs index 2c1f2bf0be4f4..a6e707cc2adea 100644 --- a/src/test/rustdoc/pub-use-extern-macros.rs +++ b/src/test/rustdoc/pub-use-extern-macros.rs @@ -15,15 +15,15 @@ extern crate macros; // @has pub_use_extern_macros/macro.bar.html -// @!has pub_use_extern_macros/index.html 'pub use macros::bar;' +// @!has pub_use_extern_macros/index.html '//code' 'pub use macros::bar;' pub use macros::bar; // @has pub_use_extern_macros/macro.baz.html -// @!has pub_use_extern_macros/index.html 'pub use macros::baz;' +// @!has pub_use_extern_macros/index.html '//code' 'pub use macros::baz;' #[doc(inline)] pub use macros::baz; // @has pub_use_extern_macros/macro.quux.html -// @!has pub_use_extern_macros/index.html 'pub use macros::quux;' +// @!has pub_use_extern_macros/index.html '//code' 'pub use macros::quux;' #[doc(hidden)] pub use macros::quux;