@@ -4,7 +4,7 @@ use std::sync::Arc;
44
55use rustc_hir:: attrs:: Deprecation ;
66use rustc_hir:: def:: { CtorKind , DefKind } ;
7- use rustc_hir:: def_id:: { CrateNum , DefId , DefIdMap , LOCAL_CRATE } ;
7+ use rustc_hir:: def_id:: { CrateNum , DefId , DefIdMap , LOCAL_CRATE , LocalDefId } ;
88use rustc_hir:: definitions:: { DefKey , DefPath , DefPathHash } ;
99use rustc_middle:: arena:: ArenaAllocatable ;
1010use rustc_middle:: bug;
@@ -18,7 +18,7 @@ use rustc_middle::util::Providers;
1818use rustc_session:: cstore:: { CrateStore , ExternCrate } ;
1919use rustc_session:: { Session , StableCrateId } ;
2020use rustc_span:: hygiene:: ExpnId ;
21- use rustc_span:: { Span , Symbol , kw} ;
21+ use rustc_span:: { Span , Symbol , kw, sym } ;
2222
2323use super :: { Decodable , DecodeContext , DecodeIterator } ;
2424use crate :: creader:: { CStore , LoadedMacro } ;
@@ -396,7 +396,7 @@ provide! { tcx, def_id, other, cdata,
396396 crate_extern_paths => { cdata. source( ) . paths( ) . cloned( ) . collect( ) }
397397 expn_that_defined => { cdata. get_expn_that_defined( def_id. index, tcx. sess) }
398398 default_field => { cdata. get_default_field( def_id. index) }
399- is_doc_hidden => { cdata. get_attr_flags( def_id. index) . contains( AttrFlags :: IS_DOC_HIDDEN ) }
399+ is_doc_hidden_q => { cdata. get_attr_flags( def_id. index) . contains( AttrFlags :: IS_DOC_HIDDEN ) }
400400 doc_link_resolutions => { tcx. arena. alloc( cdata. get_doc_link_resolutions( def_id. index) ) }
401401 doc_link_traits_in_scope => {
402402 tcx. arena. alloc_from_iter( cdata. get_doc_link_traits_in_scope( def_id. index) )
@@ -679,6 +679,29 @@ impl CrateStore for CStore {
679679 }
680680}
681681
682+ /// Determines whether an item is directly annotated with `doc(hidden)`.
683+ fn is_doc_hidden_local ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
684+ tcx. get_attrs ( def_id, sym:: doc)
685+ . filter_map ( |attr| attr. meta_item_list ( ) )
686+ . any ( |items| items. iter ( ) . any ( |item| item. has_name ( sym:: hidden) ) )
687+ }
688+
689+ // Optimization of is_doc_hidden query in case of non-incremental build.
690+ // is_doc_hidden query itself renamed into is_doc_hidden_q.
691+ #[ inline]
692+ fn is_doc_hidden ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
693+ if let Some ( local) = def_id. as_local ( ) {
694+ is_doc_hidden_local ( tcx, local)
695+ } else {
696+ let cdata = rustc_data_structures:: sync:: FreezeReadGuard :: map ( CStore :: from_tcx ( tcx) , |c| {
697+ c. get_crate_data ( def_id. krate ) . cdata
698+ } ) ;
699+ let cdata =
700+ crate :: creader:: CrateMetadataRef { cdata : & cdata, cstore : & CStore :: from_tcx ( tcx) } ;
701+ cdata. get_attr_flags ( def_id. index ) . contains ( AttrFlags :: IS_DOC_HIDDEN )
702+ }
703+ }
704+
682705fn provide_cstore_hooks ( providers : & mut Providers ) {
683706 providers. hooks . def_path_hash_to_def_id_extern = |tcx, hash, stable_crate_id| {
684707 // If this is a DefPathHash from an upstream crate, let the CrateStore map
@@ -706,4 +729,6 @@ fn provide_cstore_hooks(providers: &mut Providers) {
706729 cdata. imported_source_file ( file_index as u32 , tcx. sess ) ;
707730 }
708731 } ;
732+ providers. hooks . is_doc_hidden = is_doc_hidden;
733+ providers. is_doc_hidden_q = is_doc_hidden_local;
709734}
0 commit comments