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`
This commit is contained in:
Yuki Okushi 2023-01-13 05:47:23 +09:00 committed by GitHub
commit ea45b3ef1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 3 deletions

View File

@ -12,5 +12,6 @@ pub(crate) const STRIP_PRIV_IMPORTS: Pass = Pass {
};
pub(crate) fn strip_priv_imports(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
ImportStripper { tcx: cx.tcx }.fold_crate(krate)
let is_json_output = cx.output_format.is_json() && !cx.show_coverage;
ImportStripper { tcx: cx.tcx, is_json_output }.fold_crate(krate)
}

View File

@ -28,7 +28,8 @@ pub(crate) fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) ->
is_json_output,
tcx: cx.tcx,
};
krate = ImportStripper { tcx: cx.tcx }.fold_crate(stripper.fold_crate(krate));
krate =
ImportStripper { tcx: cx.tcx, is_json_output }.fold_crate(stripper.fold_crate(krate));
}
// strip all impls referencing private items

View File

@ -243,12 +243,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<Item> {
match *i.kind {
clean::ImportItem(imp) if imp.imported_item_is_doc_hidden(self.tcx) => None,
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) =>
{

View File

@ -0,0 +1,26 @@
// Part of <https://github.com/rust-lang/rust/issues/59368>.
// This test ensures that reexporting a `doc(hidden)` item will
// still show the reexport.
#![crate_name = "foo"]
#[doc(hidden)]
pub type Type = u32;
// @has 'foo/index.html'
// @has - '//*[@id="reexport.Type2"]/code' 'pub use crate::Type as Type2;'
pub use crate::Type as Type2;
// @count - '//*[@id="reexport.Type3"]' 0
#[doc(hidden)]
pub use crate::Type as Type3;
#[macro_export]
#[doc(hidden)]
macro_rules! foo {
() => {};
}
// This is a bug: https://github.com/rust-lang/rust/issues/59368
// @!has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
pub use crate::foo as Macro;