mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
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:
commit
ea45b3ef1d
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) =>
|
||||
{
|
||||
|
26
tests/rustdoc/reexport-doc-hidden.rs
Normal file
26
tests/rustdoc/reexport-doc-hidden.rs
Normal 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;
|
Loading…
Reference in New Issue
Block a user