@@ -508,23 +508,16 @@ fn document(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, parent: Option
508
508
if let Some ( ref name) = item. name {
509
509
info ! ( "Documenting {}" , name) ;
510
510
}
511
- document_item_info ( w, cx, item, false , parent) ;
512
- document_full ( w, item, cx, false ) ;
511
+ document_item_info ( w, cx, item, parent) ;
512
+ document_full ( w, item, cx) ;
513
513
}
514
514
515
515
/// Render md_text as markdown.
516
- fn render_markdown (
517
- w : & mut Buffer ,
518
- cx : & Context < ' _ > ,
519
- md_text : & str ,
520
- links : Vec < RenderedLink > ,
521
- is_hidden : bool ,
522
- ) {
516
+ fn render_markdown ( w : & mut Buffer , cx : & Context < ' _ > , md_text : & str , links : Vec < RenderedLink > ) {
523
517
let mut ids = cx. id_map . borrow_mut ( ) ;
524
518
write ! (
525
519
w,
526
- "<div class=\" docblock{}\" >{}</div>" ,
527
- if is_hidden { " hidden" } else { "" } ,
520
+ "<div class=\" docblock\" >{}</div>" ,
528
521
Markdown (
529
522
md_text,
530
523
& links,
@@ -544,11 +537,10 @@ fn document_short(
544
537
item : & clean:: Item ,
545
538
cx : & Context < ' _ > ,
546
539
link : AssocItemLink < ' _ > ,
547
- is_hidden : bool ,
548
540
parent : & clean:: Item ,
549
541
show_def_docs : bool ,
550
542
) {
551
- document_item_info ( w, cx, item, is_hidden , Some ( parent) ) ;
543
+ document_item_info ( w, cx, item, Some ( parent) ) ;
552
544
if !show_def_docs {
553
545
return ;
554
546
}
@@ -565,19 +557,14 @@ fn document_short(
565
557
}
566
558
}
567
559
568
- write ! (
569
- w,
570
- "<div class='docblock{}'>{}</div>" ,
571
- if is_hidden { " hidden" } else { "" } ,
572
- summary_html,
573
- ) ;
560
+ write ! ( w, "<div class='docblock'>{}</div>" , summary_html, ) ;
574
561
}
575
562
}
576
563
577
- fn document_full ( w : & mut Buffer , item : & clean:: Item , cx : & Context < ' _ > , is_hidden : bool ) {
564
+ fn document_full ( w : & mut Buffer , item : & clean:: Item , cx : & Context < ' _ > ) {
578
565
if let Some ( s) = cx. shared . maybe_collapsed_doc_value ( item) {
579
566
debug ! ( "Doc block: =====\n {}\n =====" , s) ;
580
- render_markdown ( w, cx, & s, item. links ( cx) , is_hidden ) ;
567
+ render_markdown ( w, cx, & s, item. links ( cx) ) ;
581
568
}
582
569
}
583
570
@@ -590,16 +577,11 @@ fn document_item_info(
590
577
w : & mut Buffer ,
591
578
cx : & Context < ' _ > ,
592
579
item : & clean:: Item ,
593
- is_hidden : bool ,
594
580
parent : Option < & clean:: Item > ,
595
581
) {
596
582
let item_infos = short_item_info ( item, cx, parent) ;
597
583
if !item_infos. is_empty ( ) {
598
- if is_hidden {
599
- w. write_str ( "<div class=\" item-info hidden\" >" ) ;
600
- } else {
601
- w. write_str ( "<div class=\" item-info\" >" ) ;
602
- }
584
+ w. write_str ( "<div class=\" item-info\" >" ) ;
603
585
for info in item_infos {
604
586
w. write_str ( & info) ;
605
587
}
@@ -1281,8 +1263,12 @@ fn render_impl(
1281
1263
let trait_ = i. trait_did_full ( cache) . map ( |did| & traits[ & did] ) ;
1282
1264
let mut close_tags = String :: new ( ) ;
1283
1265
1266
+ // For trait implementations, the `interesting` output contains all methods that have doc
1267
+ // comments, and the `boring` output contains all methods that do not. The distinction is
1268
+ // used to allow hiding the boring methods.
1284
1269
fn doc_impl_item (
1285
- w : & mut Buffer ,
1270
+ boring : & mut Buffer ,
1271
+ interesting : & mut Buffer ,
1286
1272
cx : & Context < ' _ > ,
1287
1273
item : & clean:: Item ,
1288
1274
parent : & clean:: Item ,
@@ -1305,15 +1291,46 @@ fn render_impl(
1305
1291
}
1306
1292
} ;
1307
1293
1308
- let ( is_hidden, extra_class) =
1309
- if ( trait_. is_none ( ) || item. doc_value ( ) . is_some ( ) || item. kind . is_type_alias ( ) )
1310
- && !is_default_item
1311
- {
1312
- ( false , "" )
1313
- } else {
1314
- ( true , " hidden" )
1315
- } ;
1316
1294
let in_trait_class = if trait_. is_some ( ) { " trait-impl" } else { "" } ;
1295
+
1296
+ let mut doc_buffer = Buffer :: empty_from ( boring) ;
1297
+ let mut info_buffer = Buffer :: empty_from ( boring) ;
1298
+ let mut short_documented = true ;
1299
+
1300
+ if render_method_item {
1301
+ if !is_default_item {
1302
+ if let Some ( t) = trait_ {
1303
+ // The trait item may have been stripped so we might not
1304
+ // find any documentation or stability for it.
1305
+ if let Some ( it) = t. items . iter ( ) . find ( |i| i. name == item. name ) {
1306
+ // We need the stability of the item from the trait
1307
+ // because impls can't have a stability.
1308
+ if item. doc_value ( ) . is_some ( ) {
1309
+ document_item_info ( & mut info_buffer, cx, it, Some ( parent) ) ;
1310
+ document_full ( & mut doc_buffer, item, cx) ;
1311
+ short_documented = false ;
1312
+ } else {
1313
+ // In case the item isn't documented,
1314
+ // provide short documentation from the trait.
1315
+ document_short ( & mut doc_buffer, it, cx, link, parent, show_def_docs) ;
1316
+ }
1317
+ }
1318
+ } else {
1319
+ document_item_info ( & mut info_buffer, cx, item, Some ( parent) ) ;
1320
+ if show_def_docs {
1321
+ document_full ( & mut doc_buffer, item, cx) ;
1322
+ short_documented = false ;
1323
+ }
1324
+ }
1325
+ } else {
1326
+ document_short ( & mut doc_buffer, item, cx, link, parent, show_def_docs) ;
1327
+ }
1328
+ }
1329
+ let w = if short_documented && trait_. is_some ( ) { interesting } else { boring } ;
1330
+
1331
+ if !doc_buffer. is_empty ( ) {
1332
+ w. write_str ( "<details class=\" rustdoc-toggle\" open><summary>" ) ;
1333
+ }
1317
1334
match * item. kind {
1318
1335
clean:: MethodItem ( ..) | clean:: TyMethodItem ( _) => {
1319
1336
// Only render when the method is not static or we allow static methods
@@ -1326,11 +1343,7 @@ fn render_impl(
1326
1343
} )
1327
1344
} )
1328
1345
. map ( |item| format ! ( "{}.{}" , item. type_( ) , name) ) ;
1329
- write ! (
1330
- w,
1331
- "<h4 id=\" {}\" class=\" {}{}{}\" >" ,
1332
- id, item_type, extra_class, in_trait_class,
1333
- ) ;
1346
+ write ! ( w, "<h4 id=\" {}\" class=\" {}{}\" >" , id, item_type, in_trait_class, ) ;
1334
1347
w. write_str ( "<code>" ) ;
1335
1348
render_assoc_item (
1336
1349
w,
@@ -1355,11 +1368,7 @@ fn render_impl(
1355
1368
clean:: TypedefItem ( ref tydef, _) => {
1356
1369
let source_id = format ! ( "{}.{}" , ItemType :: AssocType , name) ;
1357
1370
let id = cx. derive_id ( source_id. clone ( ) ) ;
1358
- write ! (
1359
- w,
1360
- "<h4 id=\" {}\" class=\" {}{}{}\" ><code>" ,
1361
- id, item_type, extra_class, in_trait_class
1362
- ) ;
1371
+ write ! ( w, "<h4 id=\" {}\" class=\" {}{}\" ><code>" , id, item_type, in_trait_class) ;
1363
1372
assoc_type (
1364
1373
w,
1365
1374
item,
@@ -1376,11 +1385,7 @@ fn render_impl(
1376
1385
clean:: AssocConstItem ( ref ty, ref default) => {
1377
1386
let source_id = format ! ( "{}.{}" , item_type, name) ;
1378
1387
let id = cx. derive_id ( source_id. clone ( ) ) ;
1379
- write ! (
1380
- w,
1381
- "<h4 id=\" {}\" class=\" {}{}{}\" ><code>" ,
1382
- id, item_type, extra_class, in_trait_class
1383
- ) ;
1388
+ write ! ( w, "<h4 id=\" {}\" class=\" {}{}\" ><code>" , id, item_type, in_trait_class) ;
1384
1389
assoc_const (
1385
1390
w,
1386
1391
item,
@@ -1405,11 +1410,7 @@ fn render_impl(
1405
1410
clean:: AssocTypeItem ( ref bounds, ref default) => {
1406
1411
let source_id = format ! ( "{}.{}" , item_type, name) ;
1407
1412
let id = cx. derive_id ( source_id. clone ( ) ) ;
1408
- write ! (
1409
- w,
1410
- "<h4 id=\" {}\" class=\" {}{}{}\" ><code>" ,
1411
- id, item_type, extra_class, in_trait_class
1412
- ) ;
1413
+ write ! ( w, "<h4 id=\" {}\" class=\" {}{}\" ><code>" , id, item_type, in_trait_class) ;
1413
1414
assoc_type (
1414
1415
w,
1415
1416
item,
@@ -1427,38 +1428,20 @@ fn render_impl(
1427
1428
_ => panic ! ( "can't make docs for trait item with name {:?}" , item. name) ,
1428
1429
}
1429
1430
1430
- if render_method_item {
1431
- if !is_default_item {
1432
- if let Some ( t) = trait_ {
1433
- // The trait item may have been stripped so we might not
1434
- // find any documentation or stability for it.
1435
- if let Some ( it) = t. items . iter ( ) . find ( |i| i. name == item. name ) {
1436
- // We need the stability of the item from the trait
1437
- // because impls can't have a stability.
1438
- if item. doc_value ( ) . is_some ( ) {
1439
- document_item_info ( w, cx, it, is_hidden, Some ( parent) ) ;
1440
- document_full ( w, item, cx, is_hidden) ;
1441
- } else {
1442
- // In case the item isn't documented,
1443
- // provide short documentation from the trait.
1444
- document_short ( w, it, cx, link, is_hidden, parent, show_def_docs) ;
1445
- }
1446
- }
1447
- } else {
1448
- document_item_info ( w, cx, item, is_hidden, Some ( parent) ) ;
1449
- if show_def_docs {
1450
- document_full ( w, item, cx, is_hidden) ;
1451
- }
1452
- }
1453
- } else {
1454
- document_short ( w, item, cx, link, is_hidden, parent, show_def_docs) ;
1455
- }
1431
+ w. push_buffer ( info_buffer) ;
1432
+ if !doc_buffer. is_empty ( ) {
1433
+ w. write_str ( "</summary>" ) ;
1434
+ w. push_buffer ( doc_buffer) ;
1435
+ w. push_str ( "</details>" ) ;
1456
1436
}
1457
1437
}
1458
1438
1459
1439
let mut impl_items = Buffer :: empty_from ( w) ;
1440
+ let mut default_impl_items = Buffer :: empty_from ( w) ;
1441
+
1460
1442
for trait_item in & i. inner_impl ( ) . items {
1461
1443
doc_impl_item (
1444
+ & mut default_impl_items,
1462
1445
& mut impl_items,
1463
1446
cx,
1464
1447
trait_item,
@@ -1475,6 +1458,7 @@ fn render_impl(
1475
1458
1476
1459
fn render_default_items (
1477
1460
w : & mut Buffer ,
1461
+ tmp_w : & mut Buffer ,
1478
1462
cx : & Context < ' _ > ,
1479
1463
t : & clean:: Trait ,
1480
1464
i : & clean:: Impl ,
@@ -1494,6 +1478,7 @@ fn render_impl(
1494
1478
1495
1479
doc_impl_item (
1496
1480
w,
1481
+ tmp_w,
1497
1482
cx,
1498
1483
trait_item,
1499
1484
parent,
@@ -1515,6 +1500,7 @@ fn render_impl(
1515
1500
if show_default_items {
1516
1501
if let Some ( t) = trait_ {
1517
1502
render_default_items (
1503
+ & mut default_impl_items,
1518
1504
& mut impl_items,
1519
1505
cx,
1520
1506
& t. trait_ ,
@@ -1527,7 +1513,7 @@ fn render_impl(
1527
1513
) ;
1528
1514
}
1529
1515
}
1530
- let details_str = if impl_items. is_empty ( ) {
1516
+ let details_str = if impl_items. is_empty ( ) && default_impl_items . is_empty ( ) {
1531
1517
""
1532
1518
} else {
1533
1519
"<details class=\" rustdoc-toggle implementors-toggle\" open><summary>"
@@ -1554,7 +1540,7 @@ fn render_impl(
1554
1540
"{}<h3 id=\" {}\" class=\" impl\" {}><code class=\" in-band\" >" ,
1555
1541
details_str, id, aliases
1556
1542
) ;
1557
- if !impl_items. is_empty ( ) {
1543
+ if !impl_items. is_empty ( ) || !default_impl_items . is_empty ( ) {
1558
1544
close_tags. insert_str ( 0 , "</details>" ) ;
1559
1545
}
1560
1546
write ! ( w, "{}" , i. inner_impl( ) . print( use_absolute, cx) ) ;
@@ -1585,7 +1571,7 @@ fn render_impl(
1585
1571
aliases,
1586
1572
i. inner_impl( ) . print( false , cx)
1587
1573
) ;
1588
- if !impl_items. is_empty ( ) {
1574
+ if !impl_items. is_empty ( ) || !default_impl_items . is_empty ( ) {
1589
1575
close_tags. insert_str ( 0 , "</details>" ) ;
1590
1576
}
1591
1577
}
@@ -1598,7 +1584,7 @@ fn render_impl(
1598
1584
outer_const_version,
1599
1585
) ;
1600
1586
write_srclink ( cx, & i. impl_item , w) ;
1601
- if impl_items. is_empty ( ) {
1587
+ if impl_items. is_empty ( ) && default_impl_items . is_empty ( ) {
1602
1588
w. write_str ( "</h3>" ) ;
1603
1589
} else {
1604
1590
w. write_str ( "</h3></summary>" ) ;
@@ -1627,8 +1613,13 @@ fn render_impl(
1627
1613
) ;
1628
1614
}
1629
1615
}
1630
- if !impl_items. is_empty ( ) {
1616
+ if !impl_items. is_empty ( ) || !default_impl_items . is_empty ( ) {
1631
1617
w. write_str ( "<div class=\" impl-items\" >" ) ;
1618
+ w. push_buffer ( default_impl_items) ;
1619
+ if trait_. is_some ( ) && !impl_items. is_empty ( ) {
1620
+ w. write_str ( "<details class=\" undocumented\" ><summary></summary>" ) ;
1621
+ close_tags. insert_str ( 0 , "</details>" ) ;
1622
+ }
1632
1623
w. push_buffer ( impl_items) ;
1633
1624
close_tags. insert_str ( 0 , "</div>" ) ;
1634
1625
}
0 commit comments