@@ -1286,7 +1286,6 @@ fn render_impl(
1286
1286
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
1287
1287
aliases : & [ String ] ,
1288
1288
) {
1289
- let tcx = cx. tcx ( ) ;
1290
1289
let cache = cx. cache ( ) ;
1291
1290
let traits = & cache. traits ;
1292
1291
let trait_ = i. trait_did_full ( cache) . map ( |did| & traits[ & did] ) ;
@@ -1558,94 +1557,34 @@ fn render_impl(
1558
1557
) ;
1559
1558
}
1560
1559
}
1561
- let toggled = !impl_items. is_empty ( ) || !default_impl_items. is_empty ( ) ;
1562
- let open_details = |close_tags : & mut String , is_collapsed : bool | {
1560
+ if render_mode == RenderMode :: Normal {
1561
+ let is_implementing_trait = i. inner_impl ( ) . trait_ . is_some ( ) ;
1562
+ let toggled = !impl_items. is_empty ( ) || !default_impl_items. is_empty ( ) ;
1563
1563
if toggled {
1564
1564
close_tags. insert_str ( 0 , "</details>" ) ;
1565
- if is_collapsed {
1566
- "<details class=\" rustdoc-toggle implementors-toggle\" ><summary>"
1565
+ if is_implementing_trait {
1566
+ write ! ( w , "<details class=\" rustdoc-toggle implementors-toggle\" >" ) ;
1567
1567
} else {
1568
- "<details class=\" rustdoc-toggle implementors-toggle\" open><summary>"
1568
+ write ! ( w , "<details class=\" rustdoc-toggle implementors-toggle\" open>" ) ;
1569
1569
}
1570
- } else {
1571
- ""
1572
1570
}
1573
- } ;
1574
- if render_mode == RenderMode :: Normal {
1575
- let is_implementing_trait;
1576
- let id = cx. derive_id ( match i. inner_impl ( ) . trait_ {
1577
- Some ( ref t) => {
1578
- is_implementing_trait = true ;
1579
- if is_on_foreign_type {
1580
- get_id_for_impl_on_foreign_type ( & i. inner_impl ( ) . for_ , t, cx)
1581
- } else {
1582
- format ! ( "impl-{}" , small_url_encode( format!( "{:#}" , t. print( cx) ) ) )
1583
- }
1584
- }
1585
- None => {
1586
- is_implementing_trait = false ;
1587
- "impl" . to_string ( )
1588
- }
1589
- } ) ;
1590
- let aliases = if aliases. is_empty ( ) {
1591
- String :: new ( )
1592
- } else {
1593
- format ! ( " data-aliases=\" {}\" " , aliases. join( "," ) )
1594
- } ;
1595
- if let Some ( use_absolute) = use_absolute {
1596
- write ! (
1597
- w,
1598
- "{}<div id=\" {}\" class=\" impl has-srclink\" {}>\
1599
- <code class=\" in-band\" >",
1600
- open_details( & mut close_tags, is_implementing_trait) ,
1601
- id,
1602
- aliases
1603
- ) ;
1604
- write ! ( w, "{}" , i. inner_impl( ) . print( use_absolute, cx) ) ;
1605
- if show_def_docs {
1606
- for it in & i. inner_impl ( ) . items {
1607
- if let clean:: TypedefItem ( ref tydef, _) = * it. kind {
1608
- w. write_str ( "<span class=\" where fmt-newline\" > " ) ;
1609
- assoc_type (
1610
- w,
1611
- it,
1612
- & [ ] ,
1613
- Some ( & tydef. type_ ) ,
1614
- AssocItemLink :: Anchor ( None ) ,
1615
- "" ,
1616
- cx,
1617
- ) ;
1618
- w. write_str ( ";</span>" ) ;
1619
- }
1620
- }
1621
- }
1622
- w. write_str ( "</code>" ) ;
1623
- } else {
1624
- write ! (
1625
- w,
1626
- "{}<div id=\" {}\" class=\" impl has-srclink\" {}>\
1627
- <code class=\" in-band\" >{}</code>",
1628
- open_details( & mut close_tags, is_implementing_trait) ,
1629
- id,
1630
- aliases,
1631
- i. inner_impl( ) . print( false , cx)
1632
- ) ;
1571
+ if toggled {
1572
+ write ! ( w, "<summary>" )
1633
1573
}
1634
- write ! ( w, "<a href=\" #{}\" class=\" anchor\" ></a>" , id) ;
1635
- render_stability_since_raw (
1574
+ render_impl_summary (
1636
1575
w,
1637
- i . impl_item . stable_since ( tcx ) . as_deref ( ) ,
1638
- i. impl_item . const_stable_since ( tcx ) . as_deref ( ) ,
1576
+ cx ,
1577
+ i,
1639
1578
outer_version,
1640
1579
outer_const_version,
1580
+ show_def_docs,
1581
+ use_absolute,
1582
+ is_on_foreign_type,
1583
+ aliases,
1641
1584
) ;
1642
- write_srclink ( cx, & i. impl_item , w) ;
1643
- if !toggled {
1644
- w. write_str ( "</div>" ) ;
1645
- } else {
1646
- w. write_str ( "</div></summary>" ) ;
1585
+ if toggled {
1586
+ write ! ( w, "</summary>" )
1647
1587
}
1648
-
1649
1588
if trait_. is_some ( ) {
1650
1589
if let Some ( portability) = portability ( & i. impl_item , Some ( parent) ) {
1651
1590
write ! ( w, "<div class=\" item-info\" >{}</div>" , portability) ;
@@ -1678,6 +1617,75 @@ fn render_impl(
1678
1617
w. write_str ( & close_tags) ;
1679
1618
}
1680
1619
1620
+ fn render_impl_summary (
1621
+ w : & mut Buffer ,
1622
+ cx : & Context < ' _ > ,
1623
+ i : & Impl ,
1624
+ outer_version : Option < & str > ,
1625
+ outer_const_version : Option < & str > ,
1626
+ show_def_docs : bool ,
1627
+ use_absolute : Option < bool > ,
1628
+ is_on_foreign_type : bool ,
1629
+ // This argument is used to reference same type with different paths to avoid duplication
1630
+ // in documentation pages for trait with automatic implementations like "Send" and "Sync".
1631
+ aliases : & [ String ] ,
1632
+ ) {
1633
+ let tcx = cx. tcx ( ) ;
1634
+ let id = cx. derive_id ( match i. inner_impl ( ) . trait_ {
1635
+ Some ( ref t) => {
1636
+ if is_on_foreign_type {
1637
+ get_id_for_impl_on_foreign_type ( & i. inner_impl ( ) . for_ , t, cx)
1638
+ } else {
1639
+ format ! ( "impl-{}" , small_url_encode( format!( "{:#}" , t. print( cx) ) ) )
1640
+ }
1641
+ }
1642
+ None => "impl" . to_string ( ) ,
1643
+ } ) ;
1644
+ let aliases = if aliases. is_empty ( ) {
1645
+ String :: new ( )
1646
+ } else {
1647
+ format ! ( " data-aliases=\" {}\" " , aliases. join( "," ) )
1648
+ } ;
1649
+ if let Some ( use_absolute) = use_absolute {
1650
+ write ! (
1651
+ w,
1652
+ "<div id=\" {}\" class=\" impl has-srclink\" {}>\
1653
+ <code class=\" in-band\" >",
1654
+ id, aliases
1655
+ ) ;
1656
+ write ! ( w, "{}" , i. inner_impl( ) . print( use_absolute, cx) ) ;
1657
+ if show_def_docs {
1658
+ for it in & i. inner_impl ( ) . items {
1659
+ if let clean:: TypedefItem ( ref tydef, _) = * it. kind {
1660
+ w. write_str ( "<span class=\" where fmt-newline\" > " ) ;
1661
+ assoc_type ( w, it, & [ ] , Some ( & tydef. type_ ) , AssocItemLink :: Anchor ( None ) , "" , cx) ;
1662
+ w. write_str ( ";</span>" ) ;
1663
+ }
1664
+ }
1665
+ }
1666
+ w. write_str ( "</code>" ) ;
1667
+ } else {
1668
+ write ! (
1669
+ w,
1670
+ "<div id=\" {}\" class=\" impl has-srclink\" {}>\
1671
+ <code class=\" in-band\" >{}</code>",
1672
+ id,
1673
+ aliases,
1674
+ i. inner_impl( ) . print( false , cx)
1675
+ ) ;
1676
+ }
1677
+ write ! ( w, "<a href=\" #{}\" class=\" anchor\" ></a>" , id) ;
1678
+ render_stability_since_raw (
1679
+ w,
1680
+ i. impl_item . stable_since ( tcx) . as_deref ( ) ,
1681
+ i. impl_item . const_stable_since ( tcx) . as_deref ( ) ,
1682
+ outer_version,
1683
+ outer_const_version,
1684
+ ) ;
1685
+ write_srclink ( cx, & i. impl_item , w) ;
1686
+ w. write_str ( "</div>" ) ;
1687
+ }
1688
+
1681
1689
fn print_sidebar ( cx : & Context < ' _ > , it : & clean:: Item , buffer : & mut Buffer ) {
1682
1690
let parentlen = cx. current . len ( ) - if it. is_mod ( ) { 1 } else { 0 } ;
1683
1691
0 commit comments