33
44use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
55use rustc_hir as hir;
6+ use rustc_hir:: CRATE_HIR_ID ;
67use rustc_hir:: def:: { DefKind , Res } ;
78use rustc_hir:: def_id:: DefId ;
89use rustc_hir:: Node ;
@@ -14,7 +15,7 @@ use rustc_span::{self, Span};
1415
1516use std:: mem;
1617
17- use crate :: clean:: { self , AttributesExt , NestedAttributesExt } ;
18+ use crate :: clean:: { self , cfg :: Cfg , AttributesExt , NestedAttributesExt } ;
1819use crate :: core;
1920use crate :: doctree:: * ;
2021
@@ -71,13 +72,14 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
7172 }
7273
7374 crate fn visit ( mut self , krate : & ' tcx hir:: Crate < ' _ > ) -> Module < ' tcx > {
75+ let tcx = self . cx . tcx ;
7476 let span = krate. item . inner ;
7577 let mut top_level_module = self . visit_mod_contents (
7678 span,
7779 & Spanned { span, node : hir:: VisibilityKind :: Public } ,
7880 hir:: CRATE_HIR_ID ,
7981 & krate. item ,
80- self . cx . tcx . crate_name ,
82+ tcx. crate_name ,
8183 ) ;
8284 // Attach the crate's exported macros to the top-level module.
8385 // In the case of macros 2.0 (`pub macro`), and for built-in `derive`s or attributes as
@@ -93,7 +95,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
9395 top_level_module. macros . push ( ( def, None ) ) ;
9496 continue ' exported_macros;
9597 }
96- let tcx = self . cx . tcx ;
9798 // Note: this is not the same as `.parent_module()`. Indeed, the latter looks
9899 // for the closest module _ancestor_, which is not necessarily a direct parent
99100 // (since a direct parent isn't necessarily a module, c.f. #77828).
@@ -123,6 +124,27 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
123124 assert_eq ! ( cur_mod_def_id, macro_parent_def_id) ;
124125 cur_mod. macros . push ( ( def, None ) ) ;
125126 }
127+
128+ self . cx . hidden_cfg = tcx. hir ( ) . attrs ( CRATE_HIR_ID )
129+ . iter ( )
130+ . filter ( |attr| attr. has_name ( sym:: doc) )
131+ . flat_map ( |attr| attr. meta_item_list ( ) . into_iter ( ) . flatten ( ) )
132+ . filter ( |attr| attr. has_name ( sym:: cfg_hide) )
133+ . flat_map ( |attr| {
134+ attr. meta_item_list ( )
135+ . unwrap_or ( & [ ] )
136+ . iter ( )
137+ . filter_map ( |attr| {
138+ Some (
139+ Cfg :: parse ( attr. meta_item ( ) ?)
140+ . map_err ( |e| self . cx . sess ( ) . diagnostic ( ) . span_err ( e. span , e. msg ) )
141+ . ok ( ) ?,
142+ )
143+ } )
144+ . collect :: < Vec < _ > > ( )
145+ } )
146+ . collect ( ) ;
147+
126148 self . cx . cache . exact_paths = self . exact_paths ;
127149 top_level_module
128150 }
0 commit comments