From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- src/librustdoc/passes/stripper.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/librustdoc/passes/stripper.rs') diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 995fb5dcc..048ed2646 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -97,17 +97,7 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> { } // handled in the `strip-priv-imports` pass - clean::ExternCrateItem { .. } => {} - clean::ImportItem(ref imp) => { - // Because json doesn't inline imports from private modules, we need to mark - // the imported item as retained so it's impls won't be stripped. - // - // FIXME: Is it necessary to check for json output here: See - // https://github.com/rust-lang/rust/pull/100325#discussion_r941495215 - if let Some(did) = imp.source.did && self.is_json_output { - self.retained.insert(did.into()); - } - } + clean::ExternCrateItem { .. } | clean::ImportItem(_) => {} clean::ImplItem(..) => {} @@ -132,7 +122,10 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> { // implementations of traits are always public. clean::ImplItem(ref imp) if imp.trait_.is_some() => true, // Variant fields have inherited visibility - clean::VariantItem(clean::Variant::Struct(..) | clean::Variant::Tuple(..)) => true, + clean::VariantItem(clean::Variant { + kind: clean::VariantKind::Struct(..) | clean::VariantKind::Tuple(..), + .. + }) => true, _ => false, }; @@ -240,11 +233,25 @@ impl<'a> DocFolder for ImplStripper<'a, '_> { /// This stripper discards all private import statements (`use`, `extern crate`) pub(crate) struct ImportStripper<'tcx> { pub(crate) tcx: TyCtxt<'tcx>, + pub(crate) is_json_output: bool, +} + +impl<'tcx> ImportStripper<'tcx> { + fn import_should_be_hidden(&self, i: &Item, imp: &clean::Import) -> bool { + if self.is_json_output { + // FIXME: This should be handled the same way as for HTML output. + imp.imported_item_is_doc_hidden(self.tcx) + } else { + i.attrs.lists(sym::doc).has_word(sym::hidden) + } + } } impl<'tcx> DocFolder for ImportStripper<'tcx> { fn fold_item(&mut self, i: Item) -> Option { match *i.kind { + clean::ImportItem(imp) if self.import_should_be_hidden(&i, &imp) => None, + clean::ImportItem(_) if i.attrs.lists(sym::doc).has_word(sym::hidden) => None, clean::ExternCrateItem { .. } | clean::ImportItem(..) if i.visibility(self.tcx) != Some(Visibility::Public) => { -- cgit v1.2.3