@@ -157,6 +157,7 @@ pub struct Cache {
157
157
priv stack : ~[ ~str ] ,
158
158
priv parent_stack : ~[ ast:: NodeId ] ,
159
159
priv search_index : ~[ IndexItem ] ,
160
+ priv privmod : bool ,
160
161
}
161
162
162
163
/// Helper struct to render all source code to HTML pages
@@ -241,6 +242,7 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
241
242
parent_stack : ~[ ] ,
242
243
search_index : ~[ ] ,
243
244
extern_locations : HashMap :: new ( ) ,
245
+ privmod : false ,
244
246
} ;
245
247
cache. stack . push ( crate . name. clone ( ) ) ;
246
248
crate = cache. fold_crate ( crate ) ;
@@ -455,6 +457,16 @@ impl<'a> SourceCollector<'a> {
455
457
456
458
impl DocFolder for Cache {
457
459
fn fold_item ( & mut self , item : clean:: Item ) -> Option < clean:: Item > {
460
+ // If this is a private module, we don't want it in the search index.
461
+ let orig_privmod = match item. inner {
462
+ clean:: ModuleItem ( ..) => {
463
+ let prev = self . privmod ;
464
+ self . privmod = prev || item. visibility != Some ( ast:: Public ) ;
465
+ prev
466
+ }
467
+ _ => self . privmod ,
468
+ } ;
469
+
458
470
// Register any generics to their corresponding string. This is used
459
471
// when pretty-printing types
460
472
match item. inner {
@@ -530,7 +542,7 @@ impl DocFolder for Cache {
530
542
_ => Some ( ( None , self . stack . as_slice ( ) ) )
531
543
} ;
532
544
match parent {
533
- Some ( ( parent, path) ) => {
545
+ Some ( ( parent, path) ) if ! self . privmod => {
534
546
self . search_index . push ( IndexItem {
535
547
ty : shortty ( & item) ,
536
548
name : s. to_owned ( ) ,
@@ -539,7 +551,7 @@ impl DocFolder for Cache {
539
551
parent : parent,
540
552
} ) ;
541
553
}
542
- None => { }
554
+ Some ( .. ) | None => { }
543
555
}
544
556
}
545
557
None => { }
@@ -612,8 +624,12 @@ impl DocFolder for Cache {
612
624
// Private modules may survive the strip-private pass if
613
625
// they contain impls for public types, but those will get
614
626
// stripped here
615
- clean:: Item { inner : clean:: ModuleItem ( ref m) , .. }
616
- if m. items . len ( ) == 0 => None ,
627
+ clean:: Item { inner : clean:: ModuleItem ( ref m) ,
628
+ visibility, .. }
629
+ if ( m. items . len ( ) == 0 &&
630
+ item. doc_value ( ) . is_none ( ) ) ||
631
+ visibility != Some ( ast:: Public ) => None ,
632
+
617
633
i => Some ( i) ,
618
634
}
619
635
}
@@ -622,6 +638,7 @@ impl DocFolder for Cache {
622
638
623
639
if pushed { self . stack . pop ( ) ; }
624
640
if parent_pushed { self . parent_stack . pop ( ) ; }
641
+ self . privmod = orig_privmod;
625
642
return ret;
626
643
}
627
644
}
@@ -1186,7 +1203,7 @@ fn item_struct(w: &mut Writer, it: &clean::Item, s: &clean::Struct) {
1186
1203
1187
1204
document ( w, it) ;
1188
1205
match s. struct_type {
1189
- doctree:: Plain => {
1206
+ doctree:: Plain if s . fields . len ( ) > 0 => {
1190
1207
write ! ( w, "<h2 class='fields'>Fields</h2>\n <table>" ) ;
1191
1208
for field in s. fields . iter ( ) {
1192
1209
write ! ( w, "<tr><td id='structfield.{name}'>\
0 commit comments