Skip to content

Commit 93bf84c

Browse files
committed
Auto merge of rust-lang#106538 - aDotInTheVoid:strip-use-doc-hidden, r=notriddle
rustdoc: Strip imports of items which are `#[doc(hidden)]` Closes rust-lang#106379
2 parents 84f22e4 + ff46d11 commit 93bf84c

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

src/librustdoc/clean/types.rs

+11
Original file line numberDiff line numberDiff line change
@@ -2494,6 +2494,17 @@ impl Import {
24942494
pub(crate) fn new_glob(source: ImportSource, should_be_displayed: bool) -> Self {
24952495
Self { kind: ImportKind::Glob, source, should_be_displayed }
24962496
}
2497+
2498+
pub(crate) fn imported_item_is_doc_hidden(&self, tcx: TyCtxt<'_>) -> bool {
2499+
match self.source.did {
2500+
Some(did) => tcx
2501+
.get_attrs(did, sym::doc)
2502+
.filter_map(ast::Attribute::meta_item_list)
2503+
.flatten()
2504+
.has_word(sym::hidden),
2505+
None => false,
2506+
}
2507+
}
24972508
}
24982509

24992510
#[derive(Clone, Debug)]

src/librustdoc/passes/stripper.rs

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ pub(crate) struct ImportStripper<'tcx> {
248248
impl<'tcx> DocFolder for ImportStripper<'tcx> {
249249
fn fold_item(&mut self, i: Item) -> Option<Item> {
250250
match *i.kind {
251+
clean::ImportItem(imp) if imp.imported_item_is_doc_hidden(self.tcx) => None,
251252
clean::ExternCrateItem { .. } | clean::ImportItem(..)
252253
if i.visibility(self.tcx) != Some(Visibility::Public) =>
253254
{

src/test/rustdoc-json/doc_hidden_failure.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ mod auto {
1414
}
1515
}
1616

17-
// @count "$.index[*][?(@.name=='builders')]" 2
17+
// @count "$.index[*][?(@.name=='builders')]" 1
18+
// @has "$.index[*][?(@.name == 'ActionRowBuilder')"]
1819
pub use auto::*;
1920

2021
pub mod builders {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/106379>
2+
3+
#![feature(no_core)]
4+
#![no_core]
5+
6+
mod repeat_n {
7+
#[doc(hidden)]
8+
pub struct RepeatN {}
9+
}
10+
11+
pub use repeat_n::RepeatN;
12+
13+
// @count "$.index[*][?(@.name=='pub_use_doc_hidden')].inner.items[*]" 0
14+
// @!has "$.index[*][?(@.kind=='struct')]"
15+
// @!has "$.index[*][?(@.kind=='import')]"

0 commit comments

Comments
 (0)