@@ -50,14 +50,23 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
50
50
let mut inserted = FxHashSet :: default ( ) ;
51
51
items. extend ( doc. foreigns . iter ( ) . map ( |( item, renamed) | {
52
52
let item = clean_maybe_renamed_foreign_item ( cx, item, * renamed) ;
53
- if let Some ( name) = item. name {
53
+ if let Some ( name) = item. name && !item . attrs . lists ( sym :: doc ) . has_word ( sym :: hidden ) {
54
54
inserted. insert ( ( item. type_ ( ) , name) ) ;
55
55
}
56
56
item
57
57
} ) ) ;
58
- items. extend ( doc. mods . iter ( ) . map ( |x| {
59
- inserted. insert ( ( ItemType :: Module , x. name ) ) ;
60
- clean_doc_module ( x, cx)
58
+ items. extend ( doc. mods . iter ( ) . filter_map ( |x| {
59
+ if !inserted. insert ( ( ItemType :: Module , x. name ) ) {
60
+ return None ;
61
+ }
62
+ let item = clean_doc_module ( x, cx) ;
63
+ if item. attrs . lists ( sym:: doc) . has_word ( sym:: hidden) {
64
+ // Hidden modules are stripped at a later stage.
65
+ // If a hidden module has the same name as a visible one, we want
66
+ // to keep both of them around.
67
+ inserted. remove ( & ( ItemType :: Module , x. name ) ) ;
68
+ }
69
+ Some ( item)
61
70
} ) ) ;
62
71
63
72
// Split up imports from all other items.
@@ -72,7 +81,7 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
72
81
}
73
82
let v = clean_maybe_renamed_item ( cx, item, * renamed) ;
74
83
for item in & v {
75
- if let Some ( name) = item. name {
84
+ if let Some ( name) = item. name && !item . attrs . lists ( sym :: doc ) . has_word ( sym :: hidden ) {
76
85
inserted. insert ( ( item. type_ ( ) , name) ) ;
77
86
}
78
87
}
0 commit comments