Rollup merge of #51011 - QuietMisdreavus:duplicitous-macros, r=ollie27

rustdoc: hide macro export statements from docs

As mentioned in https://github.com/rust-lang/rust/issues/50647, rustdoc now prints both the import statement and the macro itself when re-exporting macros. This is a stopgap solution to clean up the std docs and get something small backported into beta.

What this does: When rustdoc finds an export statement for a macro, instead of printing the export and bailing, now it will instead hide the export and bail. Until we can solve https://github.com/rust-lang/rust/issues/34843 or have a better way to find the attributes on an export statement when inlining macros, this will at least match the current behavior and clean up the re-export statements from the docs.
This commit is contained in:
kennytm 2018-05-24 16:02:47 +08:00
commit 98606cfe12
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
3 changed files with 10 additions and 2 deletions

View File

@ -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); record_extern_fqn(cx, did, clean::TypeKind::Const);
clean::ConstantItem(build_const(cx, did)) 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, _ => return None,
}; };
cx.renderinfo.borrow_mut().inlined.insert(did); cx.renderinfo.borrow_mut().inlined.insert(did);

View File

@ -219,6 +219,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
if let Some(exports) = self.cx.tcx.module_exports(def_id) { if let Some(exports) = self.cx.tcx.module_exports(def_id) {
for export in exports.iter().filter(|e| e.vis == Visibility::Public) { for export in exports.iter().filter(|e| e.vis == Visibility::Public) {
if let Def::Macro(def_id, ..) = export.def { 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 { if def_id.krate == LOCAL_CRATE {
continue // These are `krate.exported_macros`, handled in `self.visit()`. continue // These are `krate.exported_macros`, handled in `self.visit()`.
} }
@ -237,6 +239,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
unreachable!() unreachable!()
}; };
debug!("inlining macro {}", def.ident.name);
om.macros.push(Macro { om.macros.push(Macro {
def_id, def_id,
attrs: def.attrs.clone().into(), 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 // convert each exported_macro into a doc item
fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro { fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro {
debug!("visit_local_macro: {}", def.name);
let tts = def.body.trees().collect::<Vec<_>>(); let tts = def.body.trees().collect::<Vec<_>>();
// Extract the spans of all matchers. They represent the "interface" of the macro. // Extract the spans of all matchers. They represent the "interface" of the macro.
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect(); let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();

View File

@ -15,14 +15,15 @@
extern crate macros; extern crate macros;
// @has pub_use_extern_macros/macro.bar.html // @has pub_use_extern_macros/macro.bar.html
// @!has pub_use_extern_macros/index.html '//code' 'pub use macros::bar;'
pub use macros::bar; pub use macros::bar;
// @has pub_use_extern_macros/macro.baz.html // @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)] #[doc(inline)]
pub use macros::baz; pub use macros::baz;
// @has pub_use_extern_macros/macro.quux.html // @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)] #[doc(hidden)]
pub use macros::quux; pub use macros::quux;