Skip to content

Commit f39d0fc

Browse files
committed
Queryify is_doc_hidden
It came up hot on some profiling of rustdoc I did, so hopefully turning it into a query will help.
1 parent ed2a69c commit f39d0fc

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

compiler/rustc_middle/src/query/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,11 @@ rustc_queries! {
10351035
separate_provide_extern
10361036
}
10371037

1038+
/// Determines whether an item is annotated with `doc(hidden)`.
1039+
query is_doc_hidden(def_id: DefId) -> bool {
1040+
desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1041+
}
1042+
10381043
query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
10391044
desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
10401045
separate_provide_extern

compiler/rustc_middle/src/ty/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use rustc_macros::HashStable;
4141
use rustc_query_system::ich::StableHashingContext;
4242
use rustc_session::cstore::CrateStoreDyn;
4343
use rustc_span::symbol::{kw, Ident, Symbol};
44-
use rustc_span::{sym, Span};
44+
use rustc_span::Span;
4545
use rustc_target::abi::Align;
4646

4747
use std::hash::Hash;
@@ -2125,14 +2125,6 @@ impl<'tcx> TyCtxt<'tcx> {
21252125
self.sess.contains_name(&self.get_attrs(did), attr)
21262126
}
21272127

2128-
/// Determines whether an item is annotated with `doc(hidden)`.
2129-
pub fn is_doc_hidden(self, did: DefId) -> bool {
2130-
self.get_attrs(did)
2131-
.iter()
2132-
.filter_map(|attr| if attr.has_name(sym::doc) { attr.meta_item_list() } else { None })
2133-
.any(|items| items.iter().any(|item| item.has_name(sym::hidden)))
2134-
}
2135-
21362128
/// Returns `true` if this is an `auto trait`.
21372129
pub fn trait_is_auto(self, trait_def_id: DefId) -> bool {
21382130
self.trait_def(trait_def_id).has_auto_impl

compiler/rustc_middle/src/ty/util.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_hir::def::{CtorOf, DefKind, Res};
2121
use rustc_hir::def_id::DefId;
2222
use rustc_macros::HashStable;
2323
use rustc_query_system::ich::NodeIdHashingMode;
24-
use rustc_span::DUMMY_SP;
24+
use rustc_span::{sym, DUMMY_SP};
2525
use rustc_target::abi::{Integer, Size, TargetDataLayout};
2626
use smallvec::SmallVec;
2727
use std::{fmt, iter};
@@ -1154,6 +1154,14 @@ pub fn normalize_opaque_types<'tcx>(
11541154
val.fold_with(&mut visitor)
11551155
}
11561156

1157+
/// Determines whether an item is annotated with `doc(hidden)`.
1158+
pub fn is_doc_hidden(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
1159+
tcx.get_attrs(def_id)
1160+
.iter()
1161+
.filter_map(|attr| if attr.has_name(sym::doc) { attr.meta_item_list() } else { None })
1162+
.any(|items| items.iter().any(|item| item.has_name(sym::hidden)))
1163+
}
1164+
11571165
pub fn provide(providers: &mut ty::query::Providers) {
1158-
*providers = ty::query::Providers { normalize_opaque_types, ..*providers }
1166+
*providers = ty::query::Providers { normalize_opaque_types, is_doc_hidden, ..*providers }
11591167
}

0 commit comments

Comments
 (0)