]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/passes/stripper.rs
Rollup merge of #106759 - compiler-errors:revert-105255, r=cjgillot
[rust.git] / src / librustdoc / passes / stripper.rs
index 995fb5dcc1c86de89b780320701190eb25c3790d..f5501b3d5238b82c1ef80326f4a85061e0ddd0da 100644 (file)
@@ -132,7 +132,10 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
             // 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 +243,25 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
 /// 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<Item> {
         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) =>
             {