@@ -1628,55 +1628,47 @@ fn plain_summary_line(s: Option<&str>) -> String {
1628
1628
1629
1629
fn document ( w : & mut fmt:: Formatter , cx : & Context , item : & clean:: Item ) -> fmt:: Result {
1630
1630
document_stability ( w, cx, item) ?;
1631
- document_full ( w, item, cx. render_type ) ?;
1631
+ let prefix = render_assoc_const_value ( item) ;
1632
+ document_full ( w, item, cx. render_type , & prefix) ?;
1632
1633
Ok ( ( ) )
1633
1634
}
1634
1635
1635
1636
fn document_short ( w : & mut fmt:: Formatter , item : & clean:: Item , link : AssocItemLink ,
1636
- render_type : RenderType ) -> fmt:: Result {
1637
+ render_type : RenderType , prefix : & str ) -> fmt:: Result {
1637
1638
if let Some ( s) = item. doc_value ( ) {
1638
1639
let markdown = if s. contains ( '\n' ) {
1639
1640
format ! ( "{} [Read more]({})" ,
1640
1641
& plain_summary_line( Some ( s) ) , naive_assoc_href( item, link) )
1641
1642
} else {
1642
1643
format ! ( "{}" , & plain_summary_line( Some ( s) ) )
1643
1644
} ;
1644
- write ! ( w, "<div class='docblock'>{}</div>" ,
1645
- Markdown ( & markdown, render_type) ) ?;
1645
+ write ! ( w, "<div class='docblock'>{}{}</div>" , prefix, Markdown ( & markdown, render_type) ) ?;
1646
+ } else if !prefix. is_empty ( ) {
1647
+ write ! ( w, "<div class='docblock'>{}</div>" , prefix) ?;
1646
1648
}
1647
1649
Ok ( ( ) )
1648
1650
}
1649
1651
1650
- fn md_render_assoc_item ( item : & clean:: Item ) -> String {
1652
+ fn render_assoc_const_value ( item : & clean:: Item ) -> String {
1651
1653
match item. inner {
1652
- clean:: AssociatedConstItem ( ref ty, ref default) => {
1653
- if let Some ( default) = default. as_ref ( ) {
1654
- format ! ( "```\n {}: {:#} = {}\n ```\n \n " , item. name. as_ref( ) . unwrap( ) , ty, default )
1655
- } else {
1656
- format ! ( "```\n {}: {:#}\n ```\n \n " , item. name. as_ref( ) . unwrap( ) , ty)
1657
- }
1654
+ clean:: AssociatedConstItem ( ref ty, Some ( ref default) ) => {
1655
+ highlight:: render_with_highlighting (
1656
+ & format ! ( "{}: {:#} = {}" , item. name. as_ref( ) . unwrap( ) , ty, default ) ,
1657
+ None ,
1658
+ None ,
1659
+ None ,
1660
+ )
1658
1661
}
1659
1662
_ => String :: new ( ) ,
1660
1663
}
1661
1664
}
1662
1665
1663
- fn get_doc_value ( item : & clean:: Item ) -> Option < & str > {
1664
- let x = item. doc_value ( ) ;
1665
- if x. is_none ( ) {
1666
- match item. inner {
1667
- clean:: AssociatedConstItem ( _, _) => Some ( "" ) ,
1668
- _ => None ,
1669
- }
1670
- } else {
1671
- x
1672
- }
1673
- }
1674
-
1675
1666
fn document_full ( w : & mut fmt:: Formatter , item : & clean:: Item ,
1676
- render_type : RenderType ) -> fmt:: Result {
1677
- if let Some ( s) = get_doc_value ( item) {
1678
- write ! ( w, "<div class='docblock'>{}</div>" ,
1679
- Markdown ( & format!( "{}{}" , md_render_assoc_item( item) , s) , render_type) ) ?;
1667
+ render_type : RenderType , prefix : & str ) -> fmt:: Result {
1668
+ if let Some ( s) = item. doc_value ( ) {
1669
+ write ! ( w, "<div class='docblock'>{}{}</div>" , prefix, Markdown ( s, render_type) ) ?;
1670
+ } else if !prefix. is_empty ( ) {
1671
+ write ! ( w, "<div class='docblock'>{}</div>" , prefix) ?;
1680
1672
}
1681
1673
Ok ( ( ) )
1682
1674
}
@@ -2960,14 +2952,6 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2960
2952
assoc_const ( w, item, ty, default. as_ref ( ) , link. anchor ( & id) ) ?;
2961
2953
write ! ( w, "</code></span></h4>\n " ) ?;
2962
2954
}
2963
- clean:: ConstantItem ( ref c) => {
2964
- let id = derive_id ( format ! ( "{}.{}" , item_type, name) ) ;
2965
- let ns_id = derive_id ( format ! ( "{}.{}" , name, item_type. name_space( ) ) ) ;
2966
- write ! ( w, "<h4 id='{}' class=\" {}\" >" , id, item_type) ?;
2967
- write ! ( w, "<span id='{}' class='invisible'><code>" , ns_id) ?;
2968
- assoc_const ( w, item, & c. type_ , Some ( & c. expr ) , link. anchor ( & id) ) ?;
2969
- write ! ( w, "</code></span></h4>\n " ) ?;
2970
- }
2971
2955
clean:: AssociatedTypeItem ( ref bounds, ref default) => {
2972
2956
let id = derive_id ( format ! ( "{}.{}" , item_type, name) ) ;
2973
2957
let ns_id = derive_id ( format ! ( "{}.{}" , name, item_type. name_space( ) ) ) ;
@@ -2981,6 +2965,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2981
2965
}
2982
2966
2983
2967
if render_method_item || render_mode == RenderMode :: Normal {
2968
+ let prefix = render_assoc_const_value ( item) ;
2984
2969
if !is_default_item {
2985
2970
if let Some ( t) = trait_ {
2986
2971
// The trait item may have been stripped so we might not
@@ -2989,20 +2974,21 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2989
2974
// We need the stability of the item from the trait
2990
2975
// because impls can't have a stability.
2991
2976
document_stability ( w, cx, it) ?;
2992
- if get_doc_value ( item) . is_some ( ) {
2993
- document_full ( w, item, cx. render_type ) ?;
2977
+ if item. doc_value ( ) . is_some ( ) {
2978
+ document_full ( w, item, cx. render_type , & prefix ) ?;
2994
2979
} else {
2995
2980
// In case the item isn't documented,
2996
2981
// provide short documentation from the trait.
2997
- document_short ( w, it, link, cx. render_type ) ?;
2982
+ document_short ( w, it, link, cx. render_type , & prefix ) ?;
2998
2983
}
2999
2984
}
3000
2985
} else {
3001
- document ( w, cx, item) ?;
2986
+ document_stability ( w, cx, item) ?;
2987
+ document_full ( w, item, cx. render_type , & prefix) ?;
3002
2988
}
3003
2989
} else {
3004
2990
document_stability ( w, cx, item) ?;
3005
- document_short ( w, item, link, cx. render_type ) ?;
2991
+ document_short ( w, item, link, cx. render_type , & prefix ) ?;
3006
2992
}
3007
2993
}
3008
2994
Ok ( ( ) )
0 commit comments