Skip to content

rustdoc: Strip imports of items which are #[doc(hidden)] #106538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,17 @@ impl Import {
pub(crate) fn new_glob(source: ImportSource, should_be_displayed: bool) -> Self {
Self { kind: ImportKind::Glob, source, should_be_displayed }
}

pub(crate) fn imported_item_is_doc_hidden(&self, tcx: TyCtxt<'_>) -> bool {
match self.source.did {
Some(did) => tcx
.get_attrs(did, sym::doc)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason that I'm not sure of, using .lists here instead of open coding it causes panics. #106538 (comment)

I think it's to do with the difference between tcx.item_attrs and tcx.get_attrs, as this was the diff that fixed it.

.filter_map(ast::Attribute::meta_item_list)
.flatten()
.has_word(sym::hidden),
None => false,
}
}
}

#[derive(Clone, Debug)]
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/passes/stripper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ pub(crate) struct ImportStripper<'tcx> {
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::ExternCrateItem { .. } | clean::ImportItem(..)
if i.visibility(self.tcx) != Some(Visibility::Public) =>
{
Expand Down
3 changes: 2 additions & 1 deletion src/test/rustdoc-json/doc_hidden_failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ mod auto {
}
}

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

pub mod builders {
Expand Down
15 changes: 15 additions & 0 deletions src/test/rustdoc-json/reexport/pub_use_doc_hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Regression test for <https://github.com/rust-lang/rust/issues/106379>

#![feature(no_core)]
#![no_core]

mod repeat_n {
#[doc(hidden)]
pub struct RepeatN {}
}

pub use repeat_n::RepeatN;

// @count "$.index[*][?(@.name=='pub_use_doc_hidden')].inner.items[*]" 0
// @!has "$.index[*][?(@.kind=='struct')]"
// @!has "$.index[*][?(@.kind=='import')]"