Clean up "doc(hidden)" check
This commit is contained in:
parent
3c9e0705ba
commit
75e236375a
4 changed files with 17 additions and 10 deletions
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -783,6 +783,10 @@ impl Item {
|
|||
}
|
||||
attrs
|
||||
}
|
||||
|
||||
pub fn is_doc_hidden(&self) -> bool {
|
||||
self.attrs.is_doc_hidden()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) =>
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue