未验证 提交 98606cfe 编写于 作者: K kennytm

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.
......@@ -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 @@ pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec<ast::Attribu
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 @@ pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec<ast::Attribu
unreachable!()
};
debug!("inlining macro {}", def.ident.name);
om.macros.push(Macro {
def_id,
attrs: def.attrs.clone().into(),
......@@ -561,6 +564,7 @@ pub fn visit_item(&mut self, item: &hir::Item,
// 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;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册