@@ -11,6 +11,7 @@ use itertools::Itertools;
1111use rustc_hash:: { FxHashMap , FxHashSet , FxHasher } ;
1212use triomphe:: Arc ;
1313
14+ use crate :: item_scope:: ImportOrExternCrate ;
1415use crate :: {
1516 db:: DefDatabase , item_scope:: ItemInNs , nameres:: DefMap , visibility:: Visibility , AssocItemId ,
1617 ModuleDefId , ModuleId , TraitId ,
@@ -29,6 +30,8 @@ pub struct ImportInfo {
2930 pub container : ModuleId ,
3031 /// Whether the import is a trait associated item or not.
3132 pub is_trait_assoc_item : bool ,
33+ /// Whether this item is annotated with `#[doc(hidden)]`.
34+ pub is_doc_hidden : bool ,
3235}
3336
3437/// A map from publicly exported items to its name.
@@ -113,14 +116,27 @@ fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> FxIndexMap<ItemIn
113116 } ) ;
114117
115118 for ( name, per_ns) in visible_items {
116- for item in per_ns. iter_items ( ) {
119+ for ( item, import ) in per_ns. iter_items ( ) {
117120 // FIXME: Not yet used, but will be once we handle doc(hidden) import sources
118- let is_doc_hidden = false ;
121+ let attr_id = if let Some ( import) = import {
122+ match import {
123+ ImportOrExternCrate :: ExternCrate ( id) => Some ( id. into ( ) ) ,
124+ ImportOrExternCrate :: Import ( id) => Some ( id. import . into ( ) ) ,
125+ }
126+ } else {
127+ match item {
128+ ItemInNs :: Types ( id) | ItemInNs :: Values ( id) => id. try_into ( ) . ok ( ) ,
129+ ItemInNs :: Macros ( id) => Some ( id. into ( ) ) ,
130+ }
131+ } ;
132+ let is_doc_hidden =
133+ attr_id. map_or ( false , |attr_id| db. attrs ( attr_id) . has_doc_hidden ( ) ) ;
119134
120135 let import_info = ImportInfo {
121136 name : name. clone ( ) ,
122137 container : module,
123138 is_trait_assoc_item : false ,
139+ is_doc_hidden,
124140 } ;
125141
126142 match depth_map. entry ( item) {
@@ -171,10 +187,10 @@ fn collect_trait_assoc_items(
171187 trait_import_info : & ImportInfo ,
172188) {
173189 let _p = profile:: span ( "collect_trait_assoc_items" ) ;
174- for ( assoc_item_name, item) in & db. trait_data ( tr) . items {
190+ for & ( ref assoc_item_name, item) in & db. trait_data ( tr) . items {
175191 let module_def_id = match item {
176- AssocItemId :: FunctionId ( f) => ModuleDefId :: from ( * f) ,
177- AssocItemId :: ConstId ( c) => ModuleDefId :: from ( * c) ,
192+ AssocItemId :: FunctionId ( f) => ModuleDefId :: from ( f) ,
193+ AssocItemId :: ConstId ( c) => ModuleDefId :: from ( c) ,
178194 // cannot use associated type aliases directly: need a `<Struct as Trait>::TypeAlias`
179195 // qualifier, ergo no need to store it for imports in import_map
180196 AssocItemId :: TypeAliasId ( _) => {
@@ -192,6 +208,7 @@ fn collect_trait_assoc_items(
192208 container : trait_import_info. container ,
193209 name : assoc_item_name. clone ( ) ,
194210 is_trait_assoc_item : true ,
211+ is_doc_hidden : db. attrs ( item. into ( ) ) . has_doc_hidden ( ) ,
195212 } ;
196213 map. insert ( assoc_item, assoc_item_info) ;
197214 }
0 commit comments