Skip to content

Commit ea45b3e

Browse files
author
Yuki Okushi
authored
Rollup merge of #106741 - GuillaumeGomez:reexport-doc-hidden, r=notriddle
Fix reexport of `doc(hidden)` item Part of #59368. It doesn't fix the `doc(inline)` nor the `doc(hidden)` on macro. I'll do it in a follow-up PR. r? `@notriddle`
2 parents 7e5d477 + 675640c commit ea45b3e

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

src/librustdoc/passes/strip_priv_imports.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ pub(crate) const STRIP_PRIV_IMPORTS: Pass = Pass {
1212
};
1313

1414
pub(crate) fn strip_priv_imports(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
15-
ImportStripper { tcx: cx.tcx }.fold_crate(krate)
15+
let is_json_output = cx.output_format.is_json() && !cx.show_coverage;
16+
ImportStripper { tcx: cx.tcx, is_json_output }.fold_crate(krate)
1617
}

src/librustdoc/passes/strip_private.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ pub(crate) fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) ->
2828
is_json_output,
2929
tcx: cx.tcx,
3030
};
31-
krate = ImportStripper { tcx: cx.tcx }.fold_crate(stripper.fold_crate(krate));
31+
krate =
32+
ImportStripper { tcx: cx.tcx, is_json_output }.fold_crate(stripper.fold_crate(krate));
3233
}
3334

3435
// strip all impls referencing private items

src/librustdoc/passes/stripper.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,25 @@ impl<'a> DocFolder for ImplStripper<'a, '_> {
243243
/// This stripper discards all private import statements (`use`, `extern crate`)
244244
pub(crate) struct ImportStripper<'tcx> {
245245
pub(crate) tcx: TyCtxt<'tcx>,
246+
pub(crate) is_json_output: bool,
247+
}
248+
249+
impl<'tcx> ImportStripper<'tcx> {
250+
fn import_should_be_hidden(&self, i: &Item, imp: &clean::Import) -> bool {
251+
if self.is_json_output {
252+
// FIXME: This should be handled the same way as for HTML output.
253+
imp.imported_item_is_doc_hidden(self.tcx)
254+
} else {
255+
i.attrs.lists(sym::doc).has_word(sym::hidden)
256+
}
257+
}
246258
}
247259

248260
impl<'tcx> DocFolder for ImportStripper<'tcx> {
249261
fn fold_item(&mut self, i: Item) -> Option<Item> {
250262
match *i.kind {
251-
clean::ImportItem(imp) if imp.imported_item_is_doc_hidden(self.tcx) => None,
263+
clean::ImportItem(imp) if self.import_should_be_hidden(&i, &imp) => None,
264+
clean::ImportItem(_) if i.attrs.lists(sym::doc).has_word(sym::hidden) => None,
252265
clean::ExternCrateItem { .. } | clean::ImportItem(..)
253266
if i.visibility(self.tcx) != Some(Visibility::Public) =>
254267
{

tests/rustdoc/reexport-doc-hidden.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Part of <https://github.com/rust-lang/rust/issues/59368>.
2+
// This test ensures that reexporting a `doc(hidden)` item will
3+
// still show the reexport.
4+
5+
#![crate_name = "foo"]
6+
7+
#[doc(hidden)]
8+
pub type Type = u32;
9+
10+
// @has 'foo/index.html'
11+
// @has - '//*[@id="reexport.Type2"]/code' 'pub use crate::Type as Type2;'
12+
pub use crate::Type as Type2;
13+
14+
// @count - '//*[@id="reexport.Type3"]' 0
15+
#[doc(hidden)]
16+
pub use crate::Type as Type3;
17+
18+
#[macro_export]
19+
#[doc(hidden)]
20+
macro_rules! foo {
21+
() => {};
22+
}
23+
24+
// This is a bug: https://github.com/rust-lang/rust/issues/59368
25+
// @!has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
26+
pub use crate::foo as Macro;

0 commit comments

Comments
 (0)