@@ -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
}
@@ -1282,8 +1264,12 @@ fn render_impl(
1282
1264
let trait_ = i. trait_did_full ( cache) . map ( |did| & traits[ & did] ) ;
1283
1265
let mut close_tags = String :: new ( ) ;
1284
1266
1267
+ // For trait implementations, the `interesting` output contains all methods that have doc
1268
+ // comments, and the `boring` output contains all methods that do not. The distinction is
1269
+ // used to allow hiding the boring methods.
1285
1270
fn doc_impl_item (
1286
- w : & mut Buffer ,
1271
+ boring : & mut Buffer ,
1272
+ interesting : & mut Buffer ,
1287
1273
cx : & Context < ' _ > ,
1288
1274
item : & clean:: Item ,
1289
1275
parent : & clean:: Item ,
@@ -1306,15 +1292,46 @@ fn render_impl(
1306
1292
}
1307
1293
} ;
1308
1294
1309
- let ( is_hidden, extra_class) =
1310
- if ( trait_. is_none ( ) || item. doc_value ( ) . is_some ( ) || item. kind . is_type_alias ( ) )
1311
- && !is_default_item
1312
- {
1313
- ( false , "" )
1314
- } else {
1315
- ( true , " hidden" )
1316
- } ;
1317
1295
let in_trait_class = if trait_. is_some ( ) { " trait-impl" } else { "" } ;
1296
+
1297
+ let mut doc_buffer = Buffer :: empty_from ( boring) ;
1298
+ let mut info_buffer = Buffer :: empty_from ( boring) ;
1299
+ let mut short_documented = true ;
1300
+
1301
+ if render_method_item {
1302
+ if !is_default_item {
1303
+ if let Some ( t) = trait_ {
1304
+ // The trait item may have been stripped so we might not
1305
+ // find any documentation or stability for it.
1306
+ if let Some ( it) = t. items . iter ( ) . find ( |i| i. name == item. name ) {
1307
+ // We need the stability of the item from the trait
1308
+ // because impls can't have a stability.
1309
+ if item. doc_value ( ) . is_some ( ) {
1310
+ document_item_info ( & mut info_buffer, cx, it, Some ( parent) ) ;
1311
+ document_full ( & mut doc_buffer, item, cx) ;
1312
+ short_documented = false ;
1313
+ } else {
1314
+ // In case the item isn't documented,
1315
+ // provide short documentation from the trait.
1316
+ document_short ( & mut doc_buffer, it, cx, link, parent, show_def_docs) ;
1317
+ }
1318
+ }
1319
+ } else {
1320
+ document_item_info ( & mut info_buffer, cx, item, Some ( parent) ) ;
1321
+ if show_def_docs {
1322
+ document_full ( & mut doc_buffer, item, cx) ;
1323
+ short_documented = false ;
1324
+ }
1325
+ }
1326
+ } else {
1327
+ document_short ( & mut doc_buffer, item, cx, link, parent, show_def_docs) ;
1328
+ }
1329
+ }
1330
+ let w = if short_documented && trait_. is_some ( ) { interesting } else { boring } ;
1331
+
1332
+ if !doc_buffer. is_empty ( ) {
1333
+ w. write_str ( "<details class=\" rustdoc-toggle\" open><summary>" ) ;
1334
+ }
1318
1335
match * item. kind {
1319
1336
clean:: MethodItem ( ..) | clean:: TyMethodItem ( _) => {
1320
1337
// Only render when the method is not static or we allow static methods
@@ -1327,11 +1344,7 @@ fn render_impl(
1327
1344
} )
1328
1345
} )
1329
1346
. map ( |item| format ! ( "{}.{}" , item. type_( ) , name) ) ;
1330
- write ! (
1331
- w,
1332
- "<h4 id=\" {}\" class=\" {}{}{}\" >" ,
1333
- id, item_type, extra_class, in_trait_class,
1334
- ) ;
1347
+ write ! ( w, "<h4 id=\" {}\" class=\" {}{}\" >" , id, item_type, in_trait_class, ) ;
1335
1348
w. write_str ( "<code>" ) ;
1336
1349
render_assoc_item (
1337
1350
w,
@@ -1356,11 +1369,7 @@ fn render_impl(
1356
1369
clean:: TypedefItem ( ref tydef, _) => {
1357
1370
let source_id = format ! ( "{}.{}" , ItemType :: AssocType , name) ;
1358
1371
let id = cx. derive_id ( source_id. clone ( ) ) ;
1359
- write ! (
1360
- w,
1361
- "<h4 id=\" {}\" class=\" {}{}{}\" ><code>" ,
1362
- id, item_type, extra_class, in_trait_class
1363
- ) ;
1372
+ write ! ( w, "<h4 id=\" {}\" class=\" {}{}\" ><code>" , id, item_type, in_trait_class) ;
1364
1373
assoc_type (
1365
1374
w,
1366
1375
item,
@@ -1377,11 +1386,7 @@ fn render_impl(
1377
1386
clean:: AssocConstItem ( ref ty, ref default) => {
1378
1387
let source_id = format ! ( "{}.{}" , item_type, name) ;
1379
1388
let id = cx. derive_id ( source_id. clone ( ) ) ;
1380
- write ! (
1381
- w,
1382
- "<h4 id=\" {}\" class=\" {}{}{}\" ><code>" ,
1383
- id, item_type, extra_class, in_trait_class
1384
- ) ;
1389
+ write ! ( w, "<h4 id=\" {}\" class=\" {}{}\" ><code>" , id, item_type, in_trait_class) ;
1385
1390
assoc_const (
1386
1391
w,
1387
1392
item,
@@ -1406,11 +1411,7 @@ fn render_impl(
1406
1411
clean:: AssocTypeItem ( ref bounds, ref default) => {
1407
1412
let source_id = format ! ( "{}.{}" , item_type, name) ;
1408
1413
let id = cx. derive_id ( source_id. clone ( ) ) ;
1409
- write ! (
1410
- w,
1411
- "<h4 id=\" {}\" class=\" {}{}{}\" ><code>" ,
1412
- id, item_type, extra_class, in_trait_class
1413
- ) ;
1414
+ write ! ( w, "<h4 id=\" {}\" class=\" {}{}\" ><code>" , id, item_type, in_trait_class) ;
1414
1415
assoc_type (
1415
1416
w,
1416
1417
item,
@@ -1428,38 +1429,20 @@ fn render_impl(
1428
1429
_ => panic ! ( "can't make docs for trait item with name {:?}" , item. name) ,
1429
1430
}
1430
1431
1431
- if render_method_item {
1432
- if !is_default_item {
1433
- if let Some ( t) = trait_ {
1434
- // The trait item may have been stripped so we might not
1435
- // find any documentation or stability for it.
1436
- if let Some ( it) = t. items . iter ( ) . find ( |i| i. name == item. name ) {
1437
- // We need the stability of the item from the trait
1438
- // because impls can't have a stability.
1439
- if item. doc_value ( ) . is_some ( ) {
1440
- document_item_info ( w, cx, it, is_hidden, Some ( parent) ) ;
1441
- document_full ( w, item, cx, is_hidden) ;
1442
- } else {
1443
- // In case the item isn't documented,
1444
- // provide short documentation from the trait.
1445
- document_short ( w, it, cx, link, is_hidden, parent, show_def_docs) ;
1446
- }
1447
- }
1448
- } else {
1449
- document_item_info ( w, cx, item, is_hidden, Some ( parent) ) ;
1450
- if show_def_docs {
1451
- document_full ( w, item, cx, is_hidden) ;
1452
- }
1453
- }
1454
- } else {
1455
- document_short ( w, item, cx, link, is_hidden, parent, show_def_docs) ;
1456
- }
1432
+ w. push_buffer ( info_buffer) ;
1433
+ if !doc_buffer. is_empty ( ) {
1434
+ w. write_str ( "</summary>" ) ;
1435
+ w. push_buffer ( doc_buffer) ;
1436
+ w. push_str ( "</details>" ) ;
1457
1437
}
1458
1438
}
1459
1439
1460
1440
let mut impl_items = Buffer :: empty_from ( w) ;
1441
+ let mut default_impl_items = Buffer :: empty_from ( w) ;
1442
+
1461
1443
for trait_item in & i. inner_impl ( ) . items {
1462
1444
doc_impl_item (
1445
+ & mut default_impl_items,
1463
1446
& mut impl_items,
1464
1447
cx,
1465
1448
trait_item,
@@ -1475,7 +1458,8 @@ fn render_impl(
1475
1458
}
1476
1459
1477
1460
fn render_default_items (
1478
- w : & mut Buffer ,
1461
+ boring : & mut Buffer ,
1462
+ interesting : & mut Buffer ,
1479
1463
cx : & Context < ' _ > ,
1480
1464
t : & clean:: Trait ,
1481
1465
i : & clean:: Impl ,
@@ -1495,7 +1479,8 @@ fn render_impl(
1495
1479
let assoc_link = AssocItemLink :: GotoSource ( did, & provided_methods) ;
1496
1480
1497
1481
doc_impl_item (
1498
- w,
1482
+ boring,
1483
+ interesting,
1499
1484
cx,
1500
1485
trait_item,
1501
1486
parent,
@@ -1517,6 +1502,7 @@ fn render_impl(
1517
1502
if show_default_items {
1518
1503
if let Some ( t) = trait_ {
1519
1504
render_default_items (
1505
+ & mut default_impl_items,
1520
1506
& mut impl_items,
1521
1507
cx,
1522
1508
& t. trait_ ,
@@ -1529,10 +1515,14 @@ fn render_impl(
1529
1515
) ;
1530
1516
}
1531
1517
}
1532
- let details_str = if impl_items. is_empty ( ) {
1533
- ""
1534
- } else {
1535
- "<details class=\" rustdoc-toggle implementors-toggle\" open><summary>"
1518
+ let toggled = !impl_items. is_empty ( ) || !default_impl_items. is_empty ( ) ;
1519
+ let open_details = |close_tags : & mut String | {
1520
+ if toggled {
1521
+ close_tags. insert_str ( 0 , "</details>" ) ;
1522
+ "<details class=\" rustdoc-toggle implementors-toggle\" open><summary>"
1523
+ } else {
1524
+ ""
1525
+ }
1536
1526
} ;
1537
1527
if render_mode == RenderMode :: Normal {
1538
1528
let id = cx. derive_id ( match i. inner_impl ( ) . trait_ {
@@ -1554,11 +1544,10 @@ fn render_impl(
1554
1544
write ! (
1555
1545
w,
1556
1546
"{}<h3 id=\" {}\" class=\" impl\" {}><code class=\" in-band\" >" ,
1557
- details_str, id, aliases
1547
+ open_details( & mut close_tags) ,
1548
+ id,
1549
+ aliases
1558
1550
) ;
1559
- if !impl_items. is_empty ( ) {
1560
- close_tags. insert_str ( 0 , "</details>" ) ;
1561
- }
1562
1551
write ! ( w, "{}" , i. inner_impl( ) . print( use_absolute, cx) ) ;
1563
1552
if show_def_docs {
1564
1553
for it in & i. inner_impl ( ) . items {
@@ -1582,14 +1571,11 @@ fn render_impl(
1582
1571
write ! (
1583
1572
w,
1584
1573
"{}<h3 id=\" {}\" class=\" impl\" {}><code class=\" in-band\" >{}</code>" ,
1585
- details_str ,
1574
+ open_details ( & mut close_tags ) ,
1586
1575
id,
1587
1576
aliases,
1588
1577
i. inner_impl( ) . print( false , cx)
1589
1578
) ;
1590
- if !impl_items. is_empty ( ) {
1591
- close_tags. insert_str ( 0 , "</details>" ) ;
1592
- }
1593
1579
}
1594
1580
write ! ( w, "<a href=\" #{}\" class=\" anchor\" ></a>" , id) ;
1595
1581
render_stability_since_raw (
@@ -1600,7 +1586,7 @@ fn render_impl(
1600
1586
outer_const_version,
1601
1587
) ;
1602
1588
write_srclink ( cx, & i. impl_item , w) ;
1603
- if impl_items . is_empty ( ) {
1589
+ if !toggled {
1604
1590
w. write_str ( "</h3>" ) ;
1605
1591
} else {
1606
1592
w. write_str ( "</h3></summary>" ) ;
@@ -1629,8 +1615,13 @@ fn render_impl(
1629
1615
) ;
1630
1616
}
1631
1617
}
1632
- if !impl_items . is_empty ( ) {
1618
+ if toggled {
1633
1619
w. write_str ( "<div class=\" impl-items\" >" ) ;
1620
+ w. push_buffer ( default_impl_items) ;
1621
+ if trait_. is_some ( ) && !impl_items. is_empty ( ) {
1622
+ w. write_str ( "<details class=\" undocumented\" ><summary></summary>" ) ;
1623
+ close_tags. insert_str ( 0 , "</details>" ) ;
1624
+ }
1634
1625
w. push_buffer ( impl_items) ;
1635
1626
close_tags. insert_str ( 0 , "</div>" ) ;
1636
1627
}
0 commit comments