提交 f39d0fc1 编写于 作者: N Noah Lev

Queryify `is_doc_hidden`

It came up hot on some profiling of rustdoc I did, so hopefully turning
it into a query will help.
上级 ed2a69c4
......@@ -1035,6 +1035,11 @@
separate_provide_extern
}
/// Determines whether an item is annotated with `doc(hidden)`.
query is_doc_hidden(def_id: DefId) -> bool {
desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
}
query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
......
......@@ -41,7 +41,7 @@
use rustc_query_system::ich::StableHashingContext;
use rustc_session::cstore::CrateStoreDyn;
use rustc_span::symbol::{kw, Ident, Symbol};
use rustc_span::{sym, Span};
use rustc_span::Span;
use rustc_target::abi::Align;
use std::hash::Hash;
......@@ -2125,14 +2125,6 @@ pub fn has_attr(self, did: DefId, attr: Symbol) -> bool {
self.sess.contains_name(&self.get_attrs(did), attr)
}
/// Determines whether an item is annotated with `doc(hidden)`.
pub fn is_doc_hidden(self, did: DefId) -> bool {
self.get_attrs(did)
.iter()
.filter_map(|attr| if attr.has_name(sym::doc) { attr.meta_item_list() } else { None })
.any(|items| items.iter().any(|item| item.has_name(sym::hidden)))
}
/// Returns `true` if this is an `auto trait`.
pub fn trait_is_auto(self, trait_def_id: DefId) -> bool {
self.trait_def(trait_def_id).has_auto_impl
......
......@@ -21,7 +21,7 @@
use rustc_hir::def_id::DefId;
use rustc_macros::HashStable;
use rustc_query_system::ich::NodeIdHashingMode;
use rustc_span::DUMMY_SP;
use rustc_span::{sym, DUMMY_SP};
use rustc_target::abi::{Integer, Size, TargetDataLayout};
use smallvec::SmallVec;
use std::{fmt, iter};
......@@ -1154,6 +1154,14 @@ pub fn normalize_opaque_types<'tcx>(
val.fold_with(&mut visitor)
}
/// Determines whether an item is annotated with `doc(hidden)`.
pub fn is_doc_hidden(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
tcx.get_attrs(def_id)
.iter()
.filter_map(|attr| if attr.has_name(sym::doc) { attr.meta_item_list() } else { None })
.any(|items| items.iter().any(|item| item.has_name(sym::hidden)))
}
pub fn provide(providers: &mut ty::query::Providers) {
*providers = ty::query::Providers { normalize_opaque_types, ..*providers }
*providers = ty::query::Providers { normalize_opaque_types, is_doc_hidden, ..*providers }
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册