@@ -1658,6 +1658,19 @@ fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Re
16581658 Ok ( ( ) )
16591659}
16601660
1661+ fn document_short ( w : & mut fmt:: Formatter , item : & clean:: Item , link : AssocItemLink ) -> fmt:: Result {
1662+ if let Some ( s) = item. doc_value ( ) {
1663+ let markdown = if s. contains ( '\n' ) {
1664+ format ! ( "{} [Read more]({})" ,
1665+ & plain_summary_line( Some ( s) ) , naive_assoc_href( item, link) )
1666+ } else {
1667+ format ! ( "{}" , & plain_summary_line( Some ( s) ) )
1668+ } ;
1669+ write ! ( w, "<div class='docblock'>{}</div>" , Markdown ( & markdown) ) ?;
1670+ }
1671+ Ok ( ( ) )
1672+ }
1673+
16611674fn item_module ( w : & mut fmt:: Formatter , cx : & Context ,
16621675 item : & clean:: Item , items : & [ clean:: Item ] ) -> fmt:: Result {
16631676 document ( w, cx, item) ?;
@@ -2555,8 +2568,9 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
25552568 }
25562569
25572570 fn doctraititem ( w : & mut fmt:: Formatter , cx : & Context , item : & clean:: Item ,
2558- link : AssocItemLink , render_static : bool , is_default_item : bool ,
2559- outer_version : Option < & str > ) -> fmt:: Result {
2571+ link : AssocItemLink , render_static : bool ,
2572+ is_default_item : bool , outer_version : Option < & str > ,
2573+ trait_ : Option < & clean:: Trait > ) -> fmt:: Result {
25602574 let shortty = shortty ( item) ;
25612575 let name = item. name . as_ref ( ) . unwrap ( ) ;
25622576
@@ -2607,16 +2621,35 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
26072621 _ => panic ! ( "can't make docs for trait item with name {:?}" , item. name)
26082622 }
26092623
2610- if !is_default_item && ( !is_static || render_static) {
2611- document ( w, cx, item)
2612- } else {
2613- Ok ( ( ) )
2624+ if !is_static || render_static {
2625+ if !is_default_item {
2626+
2627+ if item. doc_value ( ) . is_some ( ) {
2628+ document ( w, cx, item) ?;
2629+ } else {
2630+ // In case the item isn't documented,
2631+ // provide short documentation from the trait
2632+ if let Some ( t) = trait_ {
2633+ if let Some ( it) = t. items . iter ( )
2634+ . find ( |i| i. name == item. name ) {
2635+ document_short ( w, it, link) ?;
2636+ }
2637+ }
2638+ }
2639+ } else {
2640+ document_short ( w, item, link) ?;
2641+ }
26142642 }
2643+ Ok ( ( ) )
26152644 }
26162645
2646+ let traits = & cache ( ) . traits ;
2647+ let trait_ = i. trait_did ( ) . and_then ( |did| traits. get ( & did) ) ;
2648+
26172649 write ! ( w, "<div class='impl-items'>" ) ?;
26182650 for trait_item in & i. inner_impl ( ) . items {
2619- doctraititem ( w, cx, trait_item, link, render_header, false , outer_version) ?;
2651+ doctraititem ( w, cx, trait_item, link, render_header,
2652+ false , outer_version, trait_) ?;
26202653 }
26212654
26222655 fn render_default_items ( w : & mut fmt:: Formatter ,
@@ -2634,17 +2667,15 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
26342667 let assoc_link = AssocItemLink :: GotoSource ( did, & i. provided_trait_methods ) ;
26352668
26362669 doctraititem ( w, cx, trait_item, assoc_link, render_static, true ,
2637- outer_version) ?;
2670+ outer_version, None ) ?;
26382671 }
26392672 Ok ( ( ) )
26402673 }
26412674
26422675 // If we've implemented a trait, then also emit documentation for all
26432676 // default items which weren't overridden in the implementation block.
2644- if let Some ( did) = i. trait_did ( ) {
2645- if let Some ( t) = cache ( ) . traits . get ( & did) {
2646- render_default_items ( w, cx, t, & i. inner_impl ( ) , render_header, outer_version) ?;
2647- }
2677+ if let Some ( t) = trait_ {
2678+ render_default_items ( w, cx, t, & i. inner_impl ( ) , render_header, outer_version) ?;
26482679 }
26492680 write ! ( w, "</div>" ) ?;
26502681 Ok ( ( ) )
0 commit comments