@@ -2416,12 +2416,12 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2416
2416
render_assoc_items ( w, cx, it, it. def_id , AssocItemRender :: All ) ?;
2417
2417
2418
2418
let cache = cache ( ) ;
2419
- write ! ( w , "
2419
+ let impl_header = "
2420
2420
<h2 id='implementors' class='small-section-header'>
2421
2421
Implementors<a href='#implementors' class='anchor'></a>
2422
2422
</h2>
2423
2423
<ul class='item-list' id='implementors-list'>
2424
- " ) ? ;
2424
+ " ;
2425
2425
if let Some ( implementors) = cache. implementors . get ( & it. def_id ) {
2426
2426
// The DefId is for the first Type found with that name. The bool is
2427
2427
// if any Types with the same name but different DefId have been found.
@@ -2443,7 +2443,38 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2443
2443
}
2444
2444
}
2445
2445
2446
- for implementor in implementors {
2446
+ let ( local, foreign) = implementors. iter ( )
2447
+ . partition :: < Vec < _ > , _ > ( |i| i. impl_ . for_ . def_id ( )
2448
+ . map_or ( true , |d| cache. paths . contains_key ( & d) ) ) ;
2449
+
2450
+ if !foreign. is_empty ( ) {
2451
+ write ! ( w, "
2452
+ <h2 id='foreign-impls' class='section-header'>
2453
+ Implementations on Foreign Types<a href='#foreign-impls' class='anchor'></a>
2454
+ </h2>
2455
+ " ) ?;
2456
+
2457
+ for implementor in foreign {
2458
+ // need to get from a clean::Impl to a clean::Item so i can use render_impl
2459
+ if let Some ( t_did) = implementor. impl_ . for_ . def_id ( ) {
2460
+ if let Some ( impl_item) = cache. impls . get ( & t_did) . and_then ( |i| i. iter ( )
2461
+ . find ( |i| i. impl_item . def_id == implementor. def_id ) )
2462
+ {
2463
+ let i = & impl_item. impl_item ;
2464
+ let impl_ = Impl { impl_item : i. clone ( ) } ;
2465
+ let assoc_link = AssocItemLink :: GotoSource (
2466
+ i. def_id , & implementor. impl_ . provided_trait_methods
2467
+ ) ;
2468
+ render_impl ( w, cx, & impl_, assoc_link,
2469
+ RenderMode :: Normal , i. stable_since ( ) , false ) ?;
2470
+ }
2471
+ }
2472
+ }
2473
+ }
2474
+
2475
+ write ! ( w, "{}" , impl_header) ?;
2476
+
2477
+ for implementor in local {
2447
2478
write ! ( w, "<li><code>" ) ?;
2448
2479
// If there's already another implementor that has the same abbridged name, use the
2449
2480
// full path, for example in `std::iter::ExactSizeIterator`
@@ -2465,6 +2496,10 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2465
2496
}
2466
2497
writeln ! ( w, "</code></li>" ) ?;
2467
2498
}
2499
+ } else {
2500
+ // even without any implementations to write in, we still want the heading and list, so the
2501
+ // implementors javascript file pulled in below has somewhere to write the impls into
2502
+ write ! ( w, "{}" , impl_header) ?;
2468
2503
}
2469
2504
write ! ( w, "</ul>" ) ?;
2470
2505
write ! ( w, r#"<script type="text/javascript" async
@@ -3069,7 +3104,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
3069
3104
} ;
3070
3105
for i in & non_trait {
3071
3106
render_impl ( w, cx, i, AssocItemLink :: Anchor ( None ) , render_mode,
3072
- containing_item. stable_since ( ) ) ?;
3107
+ containing_item. stable_since ( ) , true ) ?;
3073
3108
}
3074
3109
}
3075
3110
if let AssocItemRender :: DerefFor { .. } = what {
@@ -3094,7 +3129,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
3094
3129
let did = i. trait_did ( ) . unwrap ( ) ;
3095
3130
let assoc_link = AssocItemLink :: GotoSource ( did, & i. inner_impl ( ) . provided_trait_methods ) ;
3096
3131
render_impl ( w, cx, i, assoc_link,
3097
- RenderMode :: Normal , containing_item. stable_since ( ) ) ?;
3132
+ RenderMode :: Normal , containing_item. stable_since ( ) , true ) ?;
3098
3133
}
3099
3134
}
3100
3135
Ok ( ( ) )
@@ -3124,7 +3159,8 @@ fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl,
3124
3159
}
3125
3160
3126
3161
fn render_impl ( w : & mut fmt:: Formatter , cx : & Context , i : & Impl , link : AssocItemLink ,
3127
- render_mode : RenderMode , outer_version : Option < & str > ) -> fmt:: Result {
3162
+ render_mode : RenderMode , outer_version : Option < & str > ,
3163
+ show_def_docs : bool ) -> fmt:: Result {
3128
3164
if render_mode == RenderMode :: Normal {
3129
3165
let id = derive_id ( match i. inner_impl ( ) . trait_ {
3130
3166
Some ( ref t) => format ! ( "impl-{}" , Escape ( & format!( "{:#}" , t) ) ) ,
@@ -3153,7 +3189,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
3153
3189
fn doc_impl_item ( w : & mut fmt:: Formatter , cx : & Context , item : & clean:: Item ,
3154
3190
link : AssocItemLink , render_mode : RenderMode ,
3155
3191
is_default_item : bool , outer_version : Option < & str > ,
3156
- trait_ : Option < & clean:: Trait > ) -> fmt:: Result {
3192
+ trait_ : Option < & clean:: Trait > , show_def_docs : bool ) -> fmt:: Result {
3157
3193
let item_type = item. type_ ( ) ;
3158
3194
let name = item. name . as_ref ( ) . unwrap ( ) ;
3159
3195
@@ -3248,19 +3284,23 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
3248
3284
document_stability ( w, cx, it) ?;
3249
3285
if item. doc_value ( ) . is_some ( ) {
3250
3286
document_full ( w, item, cx, & prefix) ?;
3251
- } else {
3287
+ } else if show_def_docs {
3252
3288
// In case the item isn't documented,
3253
3289
// provide short documentation from the trait.
3254
3290
document_short ( w, it, link, cx, & prefix) ?;
3255
3291
}
3256
3292
}
3257
3293
} else {
3258
3294
document_stability ( w, cx, item) ?;
3259
- document_full ( w, item, cx, & prefix) ?;
3295
+ if show_def_docs {
3296
+ document_full ( w, item, cx, & prefix) ?;
3297
+ }
3260
3298
}
3261
3299
} else {
3262
3300
document_stability ( w, cx, item) ?;
3263
- document_short ( w, item, link, cx, & prefix) ?;
3301
+ if show_def_docs {
3302
+ document_short ( w, item, link, cx, & prefix) ?;
3303
+ }
3264
3304
}
3265
3305
}
3266
3306
Ok ( ( ) )
@@ -3269,18 +3309,23 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
3269
3309
let traits = & cache ( ) . traits ;
3270
3310
let trait_ = i. trait_did ( ) . and_then ( |did| traits. get ( & did) ) ;
3271
3311
3312
+ if !show_def_docs {
3313
+ write ! ( w, "<span class='docblock autohide'>" ) ?;
3314
+ }
3315
+
3272
3316
write ! ( w, "<div class='impl-items'>" ) ?;
3273
3317
for trait_item in & i. inner_impl ( ) . items {
3274
3318
doc_impl_item ( w, cx, trait_item, link, render_mode,
3275
- false , outer_version, trait_) ?;
3319
+ false , outer_version, trait_, show_def_docs ) ?;
3276
3320
}
3277
3321
3278
3322
fn render_default_items ( w : & mut fmt:: Formatter ,
3279
3323
cx : & Context ,
3280
3324
t : & clean:: Trait ,
3281
3325
i : & clean:: Impl ,
3282
3326
render_mode : RenderMode ,
3283
- outer_version : Option < & str > ) -> fmt:: Result {
3327
+ outer_version : Option < & str > ,
3328
+ show_def_docs : bool ) -> fmt:: Result {
3284
3329
for trait_item in & t. items {
3285
3330
let n = trait_item. name . clone ( ) ;
3286
3331
if i. items . iter ( ) . find ( |m| m. name == n) . is_some ( ) {
@@ -3290,17 +3335,23 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
3290
3335
let assoc_link = AssocItemLink :: GotoSource ( did, & i. provided_trait_methods ) ;
3291
3336
3292
3337
doc_impl_item ( w, cx, trait_item, assoc_link, render_mode, true ,
3293
- outer_version, None ) ?;
3338
+ outer_version, None , show_def_docs ) ?;
3294
3339
}
3295
3340
Ok ( ( ) )
3296
3341
}
3297
3342
3298
3343
// If we've implemented a trait, then also emit documentation for all
3299
3344
// default items which weren't overridden in the implementation block.
3300
3345
if let Some ( t) = trait_ {
3301
- render_default_items ( w, cx, t, & i. inner_impl ( ) , render_mode, outer_version) ?;
3346
+ render_default_items ( w, cx, t, & i. inner_impl ( ) ,
3347
+ render_mode, outer_version, show_def_docs) ?;
3302
3348
}
3303
3349
write ! ( w, "</div>" ) ?;
3350
+
3351
+ if !show_def_docs {
3352
+ write ! ( w, "</span>" ) ?;
3353
+ }
3354
+
3304
3355
Ok ( ( ) )
3305
3356
}
3306
3357
@@ -3484,6 +3535,17 @@ fn sidebar_trait(fmt: &mut fmt::Formatter, it: &clean::Item,
3484
3535
3485
3536
sidebar. push_str ( & sidebar_assoc_items ( it) ) ;
3486
3537
3538
+ let c = cache ( ) ;
3539
+
3540
+ if let Some ( implementors) = c. implementors . get ( & it. def_id ) {
3541
+ if implementors. iter ( ) . any ( |i| i. impl_ . for_ . def_id ( )
3542
+ . map_or ( false , |d| !c. paths . contains_key ( & d) ) )
3543
+ {
3544
+ sidebar. push_str ( "<li><a href=\" #foreign-impls\" >\
3545
+ Implementations on Foreign Types</a></li>") ;
3546
+ }
3547
+ }
3548
+
3487
3549
sidebar. push_str ( "<li><a href=\" #implementors\" >Implementors</a></li>" ) ;
3488
3550
3489
3551
write ! ( fmt, "<div class=\" block items\" ><ul>{}</ul></div>" , sidebar)
0 commit comments