@@ -508,23 +508,16 @@ fn document(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, parent: Option
508508 if let Some ( ref name) = item. name {
509509 info ! ( "Documenting {}" , name) ;
510510 }
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) ;
513513}
514514
515515/// 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 > ) {
523517 let mut ids = cx. id_map . borrow_mut ( ) ;
524518 write ! (
525519 w,
526- "<div class=\" docblock{}\" >{}</div>" ,
527- if is_hidden { " hidden" } else { "" } ,
520+ "<div class=\" docblock\" >{}</div>" ,
528521 Markdown (
529522 md_text,
530523 & links,
@@ -544,11 +537,10 @@ fn document_short(
544537 item : & clean:: Item ,
545538 cx : & Context < ' _ > ,
546539 link : AssocItemLink < ' _ > ,
547- is_hidden : bool ,
548540 parent : & clean:: Item ,
549541 show_def_docs : bool ,
550542) {
551- document_item_info ( w, cx, item, is_hidden , Some ( parent) ) ;
543+ document_item_info ( w, cx, item, Some ( parent) ) ;
552544 if !show_def_docs {
553545 return ;
554546 }
@@ -565,19 +557,14 @@ fn document_short(
565557 }
566558 }
567559
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, ) ;
574561 }
575562}
576563
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 < ' _ > ) {
578565 if let Some ( s) = cx. shared . maybe_collapsed_doc_value ( item) {
579566 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) ) ;
581568 }
582569}
583570
@@ -590,16 +577,11 @@ fn document_item_info(
590577 w : & mut Buffer ,
591578 cx : & Context < ' _ > ,
592579 item : & clean:: Item ,
593- is_hidden : bool ,
594580 parent : Option < & clean:: Item > ,
595581) {
596582 let item_infos = short_item_info ( item, cx, parent) ;
597583 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\" >" ) ;
603585 for info in item_infos {
604586 w. write_str ( & info) ;
605587 }
@@ -1281,8 +1263,12 @@ fn render_impl(
12811263 let trait_ = i. trait_did_full ( cache) . map ( |did| & traits[ & did] ) ;
12821264 let mut close_tags = String :: new ( ) ;
12831265
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.
12841269 fn doc_impl_item (
1285- w : & mut Buffer ,
1270+ boring : & mut Buffer ,
1271+ interesting : & mut Buffer ,
12861272 cx : & Context < ' _ > ,
12871273 item : & clean:: Item ,
12881274 parent : & clean:: Item ,
@@ -1305,15 +1291,46 @@ fn render_impl(
13051291 }
13061292 } ;
13071293
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- } ;
13161294 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+ }
13171334 match * item. kind {
13181335 clean:: MethodItem ( ..) | clean:: TyMethodItem ( _) => {
13191336 // Only render when the method is not static or we allow static methods
@@ -1326,11 +1343,7 @@ fn render_impl(
13261343 } )
13271344 } )
13281345 . 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, ) ;
13341347 w. write_str ( "<code>" ) ;
13351348 render_assoc_item (
13361349 w,
@@ -1355,11 +1368,7 @@ fn render_impl(
13551368 clean:: TypedefItem ( ref tydef, _) => {
13561369 let source_id = format ! ( "{}.{}" , ItemType :: AssocType , name) ;
13571370 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) ;
13631372 assoc_type (
13641373 w,
13651374 item,
@@ -1376,11 +1385,7 @@ fn render_impl(
13761385 clean:: AssocConstItem ( ref ty, ref default) => {
13771386 let source_id = format ! ( "{}.{}" , item_type, name) ;
13781387 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) ;
13841389 assoc_const (
13851390 w,
13861391 item,
@@ -1405,11 +1410,7 @@ fn render_impl(
14051410 clean:: AssocTypeItem ( ref bounds, ref default) => {
14061411 let source_id = format ! ( "{}.{}" , item_type, name) ;
14071412 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) ;
14131414 assoc_type (
14141415 w,
14151416 item,
@@ -1427,38 +1428,20 @@ fn render_impl(
14271428 _ => panic ! ( "can't make docs for trait item with name {:?}" , item. name) ,
14281429 }
14291430
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>" ) ;
14561436 }
14571437 }
14581438
14591439 let mut impl_items = Buffer :: empty_from ( w) ;
1440+ let mut default_impl_items = Buffer :: empty_from ( w) ;
1441+
14601442 for trait_item in & i. inner_impl ( ) . items {
14611443 doc_impl_item (
1444+ & mut default_impl_items,
14621445 & mut impl_items,
14631446 cx,
14641447 trait_item,
@@ -1475,6 +1458,7 @@ fn render_impl(
14751458
14761459 fn render_default_items (
14771460 w : & mut Buffer ,
1461+ tmp_w : & mut Buffer ,
14781462 cx : & Context < ' _ > ,
14791463 t : & clean:: Trait ,
14801464 i : & clean:: Impl ,
@@ -1494,6 +1478,7 @@ fn render_impl(
14941478
14951479 doc_impl_item (
14961480 w,
1481+ tmp_w,
14971482 cx,
14981483 trait_item,
14991484 parent,
@@ -1515,6 +1500,7 @@ fn render_impl(
15151500 if show_default_items {
15161501 if let Some ( t) = trait_ {
15171502 render_default_items (
1503+ & mut default_impl_items,
15181504 & mut impl_items,
15191505 cx,
15201506 & t. trait_ ,
@@ -1527,7 +1513,7 @@ fn render_impl(
15271513 ) ;
15281514 }
15291515 }
1530- let details_str = if impl_items. is_empty ( ) {
1516+ let details_str = if impl_items. is_empty ( ) && default_impl_items . is_empty ( ) {
15311517 ""
15321518 } else {
15331519 "<details class=\" rustdoc-toggle implementors-toggle\" open><summary>"
@@ -1554,7 +1540,7 @@ fn render_impl(
15541540 "{}<h3 id=\" {}\" class=\" impl\" {}><code class=\" in-band\" >" ,
15551541 details_str, id, aliases
15561542 ) ;
1557- if !impl_items. is_empty ( ) {
1543+ if !impl_items. is_empty ( ) || !default_impl_items . is_empty ( ) {
15581544 close_tags. insert_str ( 0 , "</details>" ) ;
15591545 }
15601546 write ! ( w, "{}" , i. inner_impl( ) . print( use_absolute, cx) ) ;
@@ -1585,7 +1571,7 @@ fn render_impl(
15851571 aliases,
15861572 i. inner_impl( ) . print( false , cx)
15871573 ) ;
1588- if !impl_items. is_empty ( ) {
1574+ if !impl_items. is_empty ( ) || !default_impl_items . is_empty ( ) {
15891575 close_tags. insert_str ( 0 , "</details>" ) ;
15901576 }
15911577 }
@@ -1598,7 +1584,7 @@ fn render_impl(
15981584 outer_const_version,
15991585 ) ;
16001586 write_srclink ( cx, & i. impl_item , w) ;
1601- if impl_items. is_empty ( ) {
1587+ if impl_items. is_empty ( ) && default_impl_items . is_empty ( ) {
16021588 w. write_str ( "</h3>" ) ;
16031589 } else {
16041590 w. write_str ( "</h3></summary>" ) ;
@@ -1627,8 +1613,13 @@ fn render_impl(
16271613 ) ;
16281614 }
16291615 }
1630- if !impl_items. is_empty ( ) {
1616+ if !impl_items. is_empty ( ) || !default_impl_items . is_empty ( ) {
16311617 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+ }
16321623 w. push_buffer ( impl_items) ;
16331624 close_tags. insert_str ( 0 , "</div>" ) ;
16341625 }
0 commit comments