@@ -245,8 +245,7 @@ pub struct Cache {
245
245
parent_stack : Vec < DefId > ,
246
246
parent_is_trait_impl : bool ,
247
247
search_index : Vec < IndexItem > ,
248
- privmod : bool ,
249
- remove_priv : bool ,
248
+ stripped_mod : bool ,
250
249
access_levels : AccessLevels < DefId > ,
251
250
deref_trait_did : Option < DefId > ,
252
251
@@ -492,8 +491,7 @@ pub fn run(mut krate: clean::Crate,
492
491
parent_is_trait_impl : false ,
493
492
extern_locations : HashMap :: new ( ) ,
494
493
primitive_locations : HashMap :: new ( ) ,
495
- remove_priv : cx. passes . contains ( "strip-private" ) ,
496
- privmod : false ,
494
+ stripped_mod : false ,
497
495
access_levels : access_levels,
498
496
orphan_methods : Vec :: new ( ) ,
499
497
traits : mem:: replace ( & mut krate. external_traits , HashMap :: new ( ) ) ,
@@ -874,7 +872,6 @@ impl<'a> DocFolder for SourceCollector<'a> {
874
872
}
875
873
} ;
876
874
}
877
-
878
875
self . fold_item_recur ( item)
879
876
}
880
877
}
@@ -938,14 +935,15 @@ impl<'a> SourceCollector<'a> {
938
935
939
936
impl DocFolder for Cache {
940
937
fn fold_item ( & mut self , item : clean:: Item ) -> Option < clean:: Item > {
941
- // If this is a private module, we don't want it in the search index.
942
- let orig_privmod = match item. inner {
943
- clean:: ModuleItem ( ..) => {
944
- let prev = self . privmod ;
945
- self . privmod = prev || ( self . remove_priv && item. visibility != Some ( hir:: Public ) ) ;
938
+ // If this is a stripped module,
939
+ // we don't want it or its children in the search index.
940
+ let orig_stripped_mod = match item. inner {
941
+ clean:: StrippedItem ( box clean:: ModuleItem ( ..) ) => {
942
+ let prev = self . stripped_mod ;
943
+ self . stripped_mod = true ;
946
944
prev
947
945
}
948
- _ => self . privmod ,
946
+ _ => self . stripped_mod ,
949
947
} ;
950
948
951
949
// Register any generics to their corresponding string. This is used
@@ -983,6 +981,7 @@ impl DocFolder for Cache {
983
981
// Index this method for searching later on
984
982
if let Some ( ref s) = item. name {
985
983
let ( parent, is_method) = match item. inner {
984
+ clean:: StrippedItem ( ..) => ( ( None , None ) , false ) ,
986
985
clean:: AssociatedConstItem ( ..) |
987
986
clean:: TypedefItem ( _, true ) if self . parent_is_trait_impl => {
988
987
// skip associated items in trait impls
@@ -1027,14 +1026,15 @@ impl DocFolder for Cache {
1027
1026
} ;
1028
1027
1029
1028
match parent {
1030
- ( parent, Some ( path) ) if is_method || ( !self . privmod && !hidden_field) => {
1029
+ ( parent, Some ( path) ) if is_method || ( !self . stripped_mod && !hidden_field) => {
1031
1030
// Needed to determine `self` type.
1032
1031
let parent_basename = self . parent_stack . first ( ) . and_then ( |parent| {
1033
1032
match self . paths . get ( parent) {
1034
1033
Some ( & ( ref fqp, _) ) => Some ( fqp[ fqp. len ( ) - 1 ] . clone ( ) ) ,
1035
1034
_ => None
1036
1035
}
1037
1036
} ) ;
1037
+ debug_assert ! ( !item. is_stripped( ) ) ;
1038
1038
1039
1039
// A crate has a module at its root, containing all items,
1040
1040
// which should not be indexed. The crate-item itself is
@@ -1051,7 +1051,7 @@ impl DocFolder for Cache {
1051
1051
} ) ;
1052
1052
}
1053
1053
}
1054
- ( Some ( parent) , None ) if is_method || ( !self . privmod && !hidden_field) => {
1054
+ ( Some ( parent) , None ) if is_method || ( !self . stripped_mod && !hidden_field) => {
1055
1055
if parent. is_local ( ) {
1056
1056
// We have a parent, but we don't know where they're
1057
1057
// defined yet. Wait for later to index this item.
@@ -1075,7 +1075,7 @@ impl DocFolder for Cache {
1075
1075
clean:: StructItem ( ..) | clean:: EnumItem ( ..) |
1076
1076
clean:: TypedefItem ( ..) | clean:: TraitItem ( ..) |
1077
1077
clean:: FunctionItem ( ..) | clean:: ModuleItem ( ..) |
1078
- clean:: ForeignFunctionItem ( ..) if !self . privmod => {
1078
+ clean:: ForeignFunctionItem ( ..) if !self . stripped_mod => {
1079
1079
// Reexported items mean that the same id can show up twice
1080
1080
// in the rustdoc ast that we're looking at. We know,
1081
1081
// however, that a reexported item doesn't show up in the
@@ -1093,7 +1093,7 @@ impl DocFolder for Cache {
1093
1093
}
1094
1094
// link variants to their parent enum because pages aren't emitted
1095
1095
// for each variant
1096
- clean:: VariantItem ( ..) if !self . privmod => {
1096
+ clean:: VariantItem ( ..) if !self . stripped_mod => {
1097
1097
let mut stack = self . stack . clone ( ) ;
1098
1098
stack. pop ( ) ;
1099
1099
self . paths . insert ( item. def_id , ( stack, ItemType :: Enum ) ) ;
@@ -1176,7 +1176,7 @@ impl DocFolder for Cache {
1176
1176
1177
1177
if pushed { self . stack . pop ( ) . unwrap ( ) ; }
1178
1178
if parent_pushed { self . parent_stack . pop ( ) . unwrap ( ) ; }
1179
- self . privmod = orig_privmod ;
1179
+ self . stripped_mod = orig_stripped_mod ;
1180
1180
self . parent_is_trait_impl = orig_parent_is_trait_impl;
1181
1181
return ret;
1182
1182
}
@@ -1233,15 +1233,12 @@ impl Context {
1233
1233
1234
1234
// render the crate documentation
1235
1235
let mut work = vec ! ( ( self , item) ) ;
1236
- loop {
1237
- match work. pop ( ) {
1238
- Some ( ( mut cx, item) ) => cx. item ( item, |cx, item| {
1239
- work. push ( ( cx. clone ( ) , item) ) ;
1240
- } ) ?,
1241
- None => break ,
1242
- }
1243
- }
1244
1236
1237
+ while let Some ( ( mut cx, item) ) = work. pop ( ) {
1238
+ cx. item ( item, |cx, item| {
1239
+ work. push ( ( cx. clone ( ) , item) )
1240
+ } ) ?
1241
+ }
1245
1242
Ok ( ( ) )
1246
1243
}
1247
1244
@@ -1296,87 +1293,80 @@ impl Context {
1296
1293
layout:: render ( & mut writer, & cx. layout , & page,
1297
1294
& Sidebar { cx : cx, item : it } ,
1298
1295
& Item { cx : cx, item : it } ) ?;
1296
+
1299
1297
} else {
1300
1298
let mut url = repeat ( "../" ) . take ( cx. current . len ( ) )
1301
1299
. collect :: < String > ( ) ;
1302
- match cache ( ) . paths . get ( & it. def_id ) {
1303
- Some ( & ( ref names, _) ) => {
1304
- for name in & names[ ..names. len ( ) - 1 ] {
1305
- url. push_str ( name) ;
1306
- url. push_str ( "/" ) ;
1307
- }
1308
- url. push_str ( & item_path ( it) ) ;
1309
- layout:: redirect ( & mut writer, & url) ?;
1300
+ if let Some ( & ( ref names, _) ) = cache ( ) . paths . get ( & it. def_id ) {
1301
+ for name in & names[ ..names. len ( ) - 1 ] {
1302
+ url. push_str ( name) ;
1303
+ url. push_str ( "/" ) ;
1310
1304
}
1311
- None => { }
1305
+ url. push_str ( & item_path ( it) ) ;
1306
+ layout:: redirect ( & mut writer, & url) ?;
1312
1307
}
1313
1308
}
1314
1309
writer. flush ( )
1315
1310
}
1316
1311
1317
- // Private modules may survive the strip-private pass if they
1318
- // contain impls for public types. These modules can also
1312
+ // Stripped modules survive the rustdoc passes (i.e. `strip-private`)
1313
+ // if they contain impls for public types. These modules can also
1319
1314
// contain items such as publicly reexported structures.
1320
1315
//
1321
1316
// External crates will provide links to these structures, so
1322
- // these modules are recursed into, but not rendered normally (a
1323
- // flag on the context).
1317
+ // these modules are recursed into, but not rendered normally
1318
+ // (a flag on the context).
1324
1319
if !self . render_redirect_pages {
1325
- self . render_redirect_pages = self . ignore_private_item ( & item) ;
1320
+ self . render_redirect_pages = self . maybe_ignore_item ( & item) ;
1326
1321
}
1327
1322
1328
- match item. inner {
1323
+ if item. is_mod ( ) {
1329
1324
// modules are special because they add a namespace. We also need to
1330
1325
// recurse into the items of the module as well.
1331
- clean:: ModuleItem ( ..) => {
1332
- let name = item. name . as_ref ( ) . unwrap ( ) . to_string ( ) ;
1333
- let mut item = Some ( item) ;
1334
- self . recurse ( name, |this| {
1335
- let item = item. take ( ) . unwrap ( ) ;
1336
- let joint_dst = this. dst . join ( "index.html" ) ;
1337
- let dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1338
- try_err ! ( render( dst, this, & item, false ) , & joint_dst) ;
1339
-
1340
- let m = match item. inner {
1341
- clean:: ModuleItem ( m) => m,
1342
- _ => unreachable ! ( )
1343
- } ;
1344
-
1345
- // render sidebar-items.js used throughout this module
1346
- {
1347
- let items = this. build_sidebar_items ( & m) ;
1348
- let js_dst = this. dst . join ( "sidebar-items.js" ) ;
1349
- let mut js_out = BufWriter :: new ( try_err ! ( File :: create( & js_dst) , & js_dst) ) ;
1350
- try_err ! ( write!( & mut js_out, "initSidebarItems({});" ,
1351
- as_json( & items) ) , & js_dst) ;
1352
- }
1326
+ let name = item. name . as_ref ( ) . unwrap ( ) . to_string ( ) ;
1327
+ let mut item = Some ( item) ;
1328
+ self . recurse ( name, |this| {
1329
+ let item = item. take ( ) . unwrap ( ) ;
1330
+ let joint_dst = this. dst . join ( "index.html" ) ;
1331
+ let dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1332
+ try_err ! ( render( dst, this, & item, false ) , & joint_dst) ;
1353
1333
1354
- for item in m. items {
1355
- f ( this, item) ;
1356
- }
1357
- Ok ( ( ) )
1358
- } )
1359
- }
1334
+ let m = match item. inner {
1335
+ clean:: StrippedItem ( box clean:: ModuleItem ( m) ) |
1336
+ clean:: ModuleItem ( m) => m,
1337
+ _ => unreachable ! ( )
1338
+ } ;
1360
1339
1361
- // Things which don't have names (like impls) don't get special
1362
- // pages dedicated to them.
1363
- _ if item. name . is_some ( ) => {
1364
- let joint_dst = self . dst . join ( & item_path ( & item) ) ;
1340
+ // render sidebar-items.js used throughout this module
1341
+ {
1342
+ let items = this. build_sidebar_items ( & m) ;
1343
+ let js_dst = this. dst . join ( "sidebar-items.js" ) ;
1344
+ let mut js_out = BufWriter :: new ( try_err ! ( File :: create( & js_dst) , & js_dst) ) ;
1345
+ try_err ! ( write!( & mut js_out, "initSidebarItems({});" ,
1346
+ as_json( & items) ) , & js_dst) ;
1347
+ }
1365
1348
1366
- let dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1367
- try_err ! ( render( dst, self , & item, true ) , & joint_dst) ;
1349
+ for item in m. items {
1350
+ f ( this, item) ;
1351
+ }
1368
1352
Ok ( ( ) )
1369
- }
1353
+ } )
1354
+ } else if item. name . is_some ( ) {
1355
+ let joint_dst = self . dst . join ( & item_path ( & item) ) ;
1370
1356
1371
- _ => Ok ( ( ) )
1357
+ let dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1358
+ try_err ! ( render( dst, self , & item, true ) , & joint_dst) ;
1359
+ Ok ( ( ) )
1360
+ } else {
1361
+ Ok ( ( ) )
1372
1362
}
1373
1363
}
1374
1364
1375
1365
fn build_sidebar_items ( & self , m : & clean:: Module ) -> BTreeMap < String , Vec < NameDoc > > {
1376
1366
// BTreeMap instead of HashMap to get a sorted output
1377
1367
let mut map = BTreeMap :: new ( ) ;
1378
1368
for item in & m. items {
1379
- if self . ignore_private_item ( item) { continue }
1369
+ if self . maybe_ignore_item ( item) { continue }
1380
1370
1381
1371
let short = shortty ( item) . to_static_str ( ) ;
1382
1372
let myname = match item. name {
@@ -1394,27 +1384,18 @@ impl Context {
1394
1384
return map;
1395
1385
}
1396
1386
1397
- fn ignore_private_item ( & self , it : & clean:: Item ) -> bool {
1387
+ fn maybe_ignore_item ( & self , it : & clean:: Item ) -> bool {
1398
1388
match it. inner {
1389
+ clean:: StrippedItem ( ..) => true ,
1399
1390
clean:: ModuleItem ( ref m) => {
1400
- ( m. items . is_empty ( ) &&
1401
- it. doc_value ( ) . is_none ( ) &&
1402
- it. visibility != Some ( hir:: Public ) ) ||
1403
- ( self . passes . contains ( "strip-private" ) && it. visibility != Some ( hir:: Public ) )
1404
- }
1405
- clean:: PrimitiveItem ( ..) => it. visibility != Some ( hir:: Public ) ,
1391
+ it. doc_value ( ) . is_none ( ) && m. items . is_empty ( ) && it. visibility != Some ( hir:: Public )
1392
+ } ,
1406
1393
_ => false ,
1407
1394
}
1408
1395
}
1409
1396
}
1410
1397
1411
1398
impl < ' a > Item < ' a > {
1412
- fn ismodule ( & self ) -> bool {
1413
- match self . item . inner {
1414
- clean:: ModuleItem ( ..) => true , _ => false
1415
- }
1416
- }
1417
-
1418
1399
/// Generate a url appropriate for an `href` attribute back to the source of
1419
1400
/// this item.
1420
1401
///
@@ -1495,6 +1476,7 @@ impl<'a> Item<'a> {
1495
1476
1496
1477
impl < ' a > fmt:: Display for Item < ' a > {
1497
1478
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
1479
+ debug_assert ! ( !self . item. is_stripped( ) ) ;
1498
1480
// Write the breadcrumb trail header for the top
1499
1481
write ! ( fmt, "\n <h1 class='fqn'><span class='in-band'>" ) ?;
1500
1482
match self . item . inner {
@@ -1516,7 +1498,7 @@ impl<'a> fmt::Display for Item<'a> {
1516
1498
} ;
1517
1499
if !is_primitive {
1518
1500
let cur = & self . cx . current ;
1519
- let amt = if self . ismodule ( ) { cur. len ( ) - 1 } else { cur. len ( ) } ;
1501
+ let amt = if self . item . is_mod ( ) { cur. len ( ) - 1 } else { cur. len ( ) } ;
1520
1502
for ( i, component) in cur. iter ( ) . enumerate ( ) . take ( amt) {
1521
1503
write ! ( fmt, "<a href='{}index.html'>{}</a>::<wbr>" ,
1522
1504
repeat( "../" ) . take( cur. len( ) - i - 1 )
@@ -1575,15 +1557,12 @@ impl<'a> fmt::Display for Item<'a> {
1575
1557
}
1576
1558
1577
1559
fn item_path ( item : & clean:: Item ) -> String {
1578
- match item. inner {
1579
- clean:: ModuleItem ( ..) => {
1580
- format ! ( "{}/index.html" , item. name. as_ref( ) . unwrap( ) )
1581
- }
1582
- _ => {
1583
- format ! ( "{}.{}.html" ,
1584
- shortty( item) . to_static_str( ) ,
1585
- * item. name. as_ref( ) . unwrap( ) )
1586
- }
1560
+ if item. is_mod ( ) {
1561
+ format ! ( "{}/index.html" , item. name. as_ref( ) . unwrap( ) )
1562
+ } else {
1563
+ format ! ( "{}.{}.html" ,
1564
+ shortty( item) . to_static_str( ) ,
1565
+ * item. name. as_ref( ) . unwrap( ) )
1587
1566
}
1588
1567
}
1589
1568
@@ -1626,7 +1605,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1626
1605
document ( w, cx, item) ?;
1627
1606
1628
1607
let mut indices = ( 0 ..items. len ( ) ) . filter ( |i| {
1629
- !cx. ignore_private_item ( & items[ * i] )
1608
+ !cx. maybe_ignore_item ( & items[ * i] )
1630
1609
} ) . collect :: < Vec < usize > > ( ) ;
1631
1610
1632
1611
// the order of item types in the listing
@@ -1670,6 +1649,9 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1670
1649
let mut curty = None ;
1671
1650
for & idx in & indices {
1672
1651
let myitem = & items[ idx] ;
1652
+ if myitem. is_stripped ( ) {
1653
+ continue ;
1654
+ }
1673
1655
1674
1656
let myty = Some ( shortty ( myitem) ) ;
1675
1657
if curty == Some ( ItemType :: ExternCrate ) && myty == Some ( ItemType :: Import ) {
@@ -2146,6 +2128,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
2146
2128
where_clause = WhereClause ( g) )
2147
2129
}
2148
2130
match item. inner {
2131
+ clean:: StrippedItem ( ..) => Ok ( ( ) ) ,
2149
2132
clean:: TyMethodItem ( ref m) => {
2150
2133
method ( w, item, m. unsafety , hir:: Constness :: NotConst ,
2151
2134
m. abi , & m. generics , & m. self_ , & m. decl , link)
@@ -2540,6 +2523,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2540
2523
assoc_type ( w, item, bounds, default. as_ref ( ) , link) ?;
2541
2524
write ! ( w, "</code></h4>\n " ) ?;
2542
2525
}
2526
+ clean:: StrippedItem ( ..) => return Ok ( ( ) ) ,
2543
2527
_ => panic ! ( "can't make docs for trait item with name {:?}" , item. name)
2544
2528
}
2545
2529
0 commit comments