Skip to content
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

Clean up "doc(hidden)" check #112799

Merged
merged 1 commit into from
Jun 20, 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
6 changes: 3 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
let mut inserted = FxHashSet::default();
items.extend(doc.foreigns.iter().map(|(item, renamed)| {
let item = clean_maybe_renamed_foreign_item(cx, item, *renamed);
if let Some(name) = item.name && !item.attrs.lists(sym::doc).has_word(sym::hidden) {
if let Some(name) = item.name && !item.is_doc_hidden() {
inserted.insert((item.type_(), name));
}
item
Expand All @@ -64,7 +64,7 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
return None;
}
let item = clean_doc_module(x, cx);
if item.attrs.lists(sym::doc).has_word(sym::hidden) {
if item.is_doc_hidden() {
// Hidden modules are stripped at a later stage.
// If a hidden module has the same name as a visible one, we want
// to keep both of them around.
Expand All @@ -85,7 +85,7 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
}
let v = clean_maybe_renamed_item(cx, item, *renamed, *import_id);
for item in &v {
if let Some(name) = item.name && !item.attrs.lists(sym::doc).has_word(sym::hidden) {
if let Some(name) = item.name && !item.is_doc_hidden() {
inserted.insert((item.type_(), name));
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,10 @@ impl Item {
}
attrs
}

pub fn is_doc_hidden(&self) -> bool {
self.attrs.is_doc_hidden()
}
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -1129,6 +1133,10 @@ impl Attributes {
false
}

fn is_doc_hidden(&self) -> bool {
self.has_doc_flag(sym::hidden)
}

pub(crate) fn from_ast(attrs: &[ast::Attribute]) -> Attributes {
Attributes::from_ast_iter(attrs.iter().map(|attr| (attr, None)), false)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/strip_hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_span::symbol::sym;
use std::mem;

use crate::clean;
use crate::clean::{Item, ItemIdSet, NestedAttributesExt};
use crate::clean::{Item, ItemIdSet};
use crate::core::DocContext;
use crate::fold::{strip_item, DocFolder};
use crate::passes::{ImplStripper, Pass};
Expand Down Expand Up @@ -85,7 +85,7 @@ impl<'a, 'tcx> Stripper<'a, 'tcx> {

impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
fn fold_item(&mut self, i: Item) -> Option<Item> {
let has_doc_hidden = i.attrs.lists(sym::doc).has_word(sym::hidden);
let has_doc_hidden = i.is_doc_hidden();
let is_impl_or_exported_macro = match *i.kind {
clean::ImplItem(..) => true,
// If the macro has the `#[macro_export]` attribute, it means it's accessible at the
Expand Down
9 changes: 4 additions & 5 deletions src/librustdoc/passes/stripper.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! A collection of utility functions for the `strip_*` passes.
use rustc_hir::def_id::DefId;
use rustc_middle::ty::{TyCtxt, Visibility};
use rustc_span::symbol::sym;
use std::mem;

use crate::clean::{self, Item, ItemId, ItemIdSet, NestedAttributesExt};
use crate::clean::{self, Item, ItemId, ItemIdSet};
use crate::fold::{strip_item, DocFolder};
use crate::formats::cache::Cache;
use crate::visit_lib::RustdocEffectiveVisibilities;
Expand Down Expand Up @@ -163,7 +162,7 @@ impl<'a> ImplStripper<'a, '_> {
// If the "for" item is exported and the impl block isn't `#[doc(hidden)]`, then we
// need to keep it.
self.cache.effective_visibilities.is_exported(self.tcx, for_def_id)
&& !item.attrs.lists(sym::doc).has_word(sym::hidden)
&& !item.is_doc_hidden()
} else {
false
}
Expand Down Expand Up @@ -240,7 +239,7 @@ impl<'tcx> ImportStripper<'tcx> {
// 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)
i.is_doc_hidden()
}
}
}
Expand All @@ -249,7 +248,7 @@ 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::ImportItem(_) if i.is_doc_hidden() => None,
clean::ExternCrateItem { .. } | clean::ImportItem(..)
if i.visibility(self.tcx) != Some(Visibility::Public) =>
{
Expand Down