mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
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:
commit
98606cfe12
@ -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);
|
||||
|
@ -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::<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();
|
||||
|
@ -15,14 +15,15 @@
|
||||
extern crate macros;
|
||||
|
||||
// @has pub_use_extern_macros/macro.bar.html
|
||||
// @!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;
|
||||
|
Loading…
Reference in New Issue
Block a user