Skip to content

Commit 2633d5f

Browse files
Fix not displayed re-export of doc(hidden) item
1 parent 606c390 commit 2633d5f

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-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
{

0 commit comments

Comments
 (0)