Skip to content

Commit 75e2363

Browse files
Clean up "doc(hidden)" check
1 parent 3c9e070 commit 75e2363

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/librustdoc/clean/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
5454
let mut inserted = FxHashSet::default();
5555
items.extend(doc.foreigns.iter().map(|(item, renamed)| {
5656
let item = clean_maybe_renamed_foreign_item(cx, item, *renamed);
57-
if let Some(name) = item.name && !item.attrs.lists(sym::doc).has_word(sym::hidden) {
57+
if let Some(name) = item.name && !item.is_doc_hidden() {
5858
inserted.insert((item.type_(), name));
5959
}
6060
item
@@ -64,7 +64,7 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
6464
return None;
6565
}
6666
let item = clean_doc_module(x, cx);
67-
if item.attrs.lists(sym::doc).has_word(sym::hidden) {
67+
if item.is_doc_hidden() {
6868
// Hidden modules are stripped at a later stage.
6969
// If a hidden module has the same name as a visible one, we want
7070
// to keep both of them around.
@@ -85,7 +85,7 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
8585
}
8686
let v = clean_maybe_renamed_item(cx, item, *renamed, *import_id);
8787
for item in &v {
88-
if let Some(name) = item.name && !item.attrs.lists(sym::doc).has_word(sym::hidden) {
88+
if let Some(name) = item.name && !item.is_doc_hidden() {
8989
inserted.insert((item.type_(), name));
9090
}
9191
}

src/librustdoc/clean/types.rs

+8
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,10 @@ impl Item {
783783
}
784784
attrs
785785
}
786+
787+
pub fn is_doc_hidden(&self) -> bool {
788+
self.attrs.is_doc_hidden()
789+
}
786790
}
787791

788792
#[derive(Clone, Debug)]
@@ -1129,6 +1133,10 @@ impl Attributes {
11291133
false
11301134
}
11311135

1136+
fn is_doc_hidden(&self) -> bool {
1137+
self.has_doc_flag(sym::hidden)
1138+
}
1139+
11321140
pub(crate) fn from_ast(attrs: &[ast::Attribute]) -> Attributes {
11331141
Attributes::from_ast_iter(attrs.iter().map(|attr| (attr, None)), false)
11341142
}

src/librustdoc/passes/strip_hidden.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_span::symbol::sym;
66
use std::mem;
77

88
use crate::clean;
9-
use crate::clean::{Item, ItemIdSet, NestedAttributesExt};
9+
use crate::clean::{Item, ItemIdSet};
1010
use crate::core::DocContext;
1111
use crate::fold::{strip_item, DocFolder};
1212
use crate::passes::{ImplStripper, Pass};
@@ -85,7 +85,7 @@ impl<'a, 'tcx> Stripper<'a, 'tcx> {
8585

8686
impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
8787
fn fold_item(&mut self, i: Item) -> Option<Item> {
88-
let has_doc_hidden = i.attrs.lists(sym::doc).has_word(sym::hidden);
88+
let has_doc_hidden = i.is_doc_hidden();
8989
let is_impl_or_exported_macro = match *i.kind {
9090
clean::ImplItem(..) => true,
9191
// If the macro has the `#[macro_export]` attribute, it means it's accessible at the

src/librustdoc/passes/stripper.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! A collection of utility functions for the `strip_*` passes.
22
use rustc_hir::def_id::DefId;
33
use rustc_middle::ty::{TyCtxt, Visibility};
4-
use rustc_span::symbol::sym;
54
use std::mem;
65

7-
use crate::clean::{self, Item, ItemId, ItemIdSet, NestedAttributesExt};
6+
use crate::clean::{self, Item, ItemId, ItemIdSet};
87
use crate::fold::{strip_item, DocFolder};
98
use crate::formats::cache::Cache;
109
use crate::visit_lib::RustdocEffectiveVisibilities;
@@ -163,7 +162,7 @@ impl<'a> ImplStripper<'a, '_> {
163162
// If the "for" item is exported and the impl block isn't `#[doc(hidden)]`, then we
164163
// need to keep it.
165164
self.cache.effective_visibilities.is_exported(self.tcx, for_def_id)
166-
&& !item.attrs.lists(sym::doc).has_word(sym::hidden)
165+
&& !item.is_doc_hidden()
167166
} else {
168167
false
169168
}
@@ -240,7 +239,7 @@ impl<'tcx> ImportStripper<'tcx> {
240239
// FIXME: This should be handled the same way as for HTML output.
241240
imp.imported_item_is_doc_hidden(self.tcx)
242241
} else {
243-
i.attrs.lists(sym::doc).has_word(sym::hidden)
242+
i.is_doc_hidden()
244243
}
245244
}
246245
}
@@ -249,7 +248,7 @@ impl<'tcx> DocFolder for ImportStripper<'tcx> {
249248
fn fold_item(&mut self, i: Item) -> Option<Item> {
250249
match *i.kind {
251250
clean::ImportItem(imp) if self.import_should_be_hidden(&i, &imp) => None,
252-
clean::ImportItem(_) if i.attrs.lists(sym::doc).has_word(sym::hidden) => None,
251+
clean::ImportItem(_) if i.is_doc_hidden() => None,
253252
clean::ExternCrateItem { .. } | clean::ImportItem(..)
254253
if i.visibility(self.tcx) != Some(Visibility::Public) =>
255254
{

0 commit comments

Comments
 (0)