Skip to content

Commit 98606cf

Browse files
committed
Rollup merge of #51011 - QuietMisdreavus:duplicitous-macros, r=ollie27
rustdoc: hide macro export statements from docs As mentioned in #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 #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.
2 parents 99de8ab + 4cf0c5f commit 98606cf

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/librustdoc/clean/inline.rs

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa
9797
record_extern_fqn(cx, did, clean::TypeKind::Const);
9898
clean::ConstantItem(build_const(cx, did))
9999
}
100+
// Macros are eagerly inlined back in visit_ast, don't show their export statements
101+
// FIXME(50647): the eager inline does not take doc(hidden)/doc(no_inline) into account
102+
Def::Macro(..) => return Some(Vec::new()),
100103
_ => return None,
101104
};
102105
cx.renderinfo.borrow_mut().inlined.insert(did);

src/librustdoc/visit_ast.rs

+4
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
219219
if let Some(exports) = self.cx.tcx.module_exports(def_id) {
220220
for export in exports.iter().filter(|e| e.vis == Visibility::Public) {
221221
if let Def::Macro(def_id, ..) = export.def {
222+
// FIXME(50647): this eager macro inlining does not take
223+
// doc(hidden)/doc(no_inline) into account
222224
if def_id.krate == LOCAL_CRATE {
223225
continue // These are `krate.exported_macros`, handled in `self.visit()`.
224226
}
@@ -237,6 +239,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
237239
unreachable!()
238240
};
239241

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

562565
// convert each exported_macro into a doc item
563566
fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro {
567+
debug!("visit_local_macro: {}", def.name);
564568
let tts = def.body.trees().collect::<Vec<_>>();
565569
// Extract the spans of all matchers. They represent the "interface" of the macro.
566570
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();

src/test/rustdoc/pub-use-extern-macros.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
extern crate macros;
1616

1717
// @has pub_use_extern_macros/macro.bar.html
18+
// @!has pub_use_extern_macros/index.html '//code' 'pub use macros::bar;'
1819
pub use macros::bar;
1920

2021
// @has pub_use_extern_macros/macro.baz.html
21-
// @!has pub_use_extern_macros/index.html 'pub use macros::baz;'
22+
// @!has pub_use_extern_macros/index.html '//code' 'pub use macros::baz;'
2223
#[doc(inline)]
2324
pub use macros::baz;
2425

2526
// @has pub_use_extern_macros/macro.quux.html
26-
// @!has pub_use_extern_macros/index.html 'pub use macros::quux;'
27+
// @!has pub_use_extern_macros/index.html '//code' 'pub use macros::quux;'
2728
#[doc(hidden)]
2829
pub use macros::quux;

0 commit comments

Comments
 (0)