@@ -1613,6 +1613,7 @@ fn render_impl(
1613
1613
) ;
1614
1614
write ! ( w, "<summary>" )
1615
1615
}
1616
+
1616
1617
render_impl_summary (
1617
1618
w,
1618
1619
cx,
@@ -1691,7 +1692,7 @@ pub(crate) fn render_impl_summary(
1691
1692
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
1692
1693
aliases : & [ String ] ,
1693
1694
) {
1694
- let id = cx. derive_id ( match i. inner_impl ( ) . trait_ {
1695
+ let html_id = cx. derive_id ( match i. inner_impl ( ) . trait_ {
1695
1696
Some ( ref t) => {
1696
1697
if is_on_foreign_type {
1697
1698
get_id_for_impl_on_foreign_type ( & i. inner_impl ( ) . for_ , t, cx)
@@ -1701,14 +1702,17 @@ pub(crate) fn render_impl_summary(
1701
1702
}
1702
1703
None => "impl" . to_string ( ) ,
1703
1704
} ) ;
1705
+
1706
+ cx. item_to_html_id_map . borrow_mut ( ) . insert ( i. impl_item . def_id , html_id. clone ( ) ) ;
1707
+
1704
1708
let aliases = if aliases. is_empty ( ) {
1705
1709
String :: new ( )
1706
1710
} else {
1707
1711
format ! ( " data-aliases=\" {}\" " , aliases. join( "," ) )
1708
1712
} ;
1709
- write ! ( w, "<div id=\" {}\" class=\" impl has-srclink\" {}>" , id , aliases) ;
1713
+ write ! ( w, "<div id=\" {}\" class=\" impl has-srclink\" {}>" , html_id , aliases) ;
1710
1714
render_rightside ( w, cx, & i. impl_item , containing_item) ;
1711
- write ! ( w, "<a href=\" #{}\" class=\" anchor\" ></a>" , id ) ;
1715
+ write ! ( w, "<a href=\" #{}\" class=\" anchor\" ></a>" , html_id ) ;
1712
1716
write ! ( w, "<h3 class=\" code-header in-band\" >" ) ;
1713
1717
1714
1718
if let Some ( use_absolute) = use_absolute {
@@ -2214,20 +2218,12 @@ fn get_id_for_impl_on_foreign_type(
2214
2218
small_url_encode ( format ! ( "impl-{:#}-for-{:#}" , trait_. print( cx) , for_. print( cx) ) )
2215
2219
}
2216
2220
2217
- fn extract_for_impl_name ( item : & clean:: Item , cx : & Context < ' _ > ) -> Option < ( String , String ) > {
2218
- match * item. kind {
2219
- clean:: ItemKind :: ImplItem ( ref i) => {
2220
- i. trait_ . as_ref ( ) . map ( |trait_| {
2221
- // Alternative format produces no URLs,
2222
- // so this parameter does nothing.
2223
- (
2224
- format ! ( "{:#}" , i. for_. print( cx) ) ,
2225
- get_id_for_impl_on_foreign_type ( & i. for_ , trait_, cx) ,
2226
- )
2227
- } )
2228
- }
2229
- _ => None ,
2230
- }
2221
+ fn extract_for_impl_name ( item : & Impl , cx : & Context < ' _ > ) -> ( String , String ) {
2222
+ let i = item. inner_impl ( ) ;
2223
+ let trait_ = i. trait_ . as_ref ( ) . unwrap ( ) ;
2224
+ // Alternative format produces no URLs,
2225
+ // so this parameter does nothing.
2226
+ ( format ! ( "{:#}" , i. for_. print( cx) ) , get_id_for_impl_on_foreign_type ( & i. for_ , trait_, cx) )
2231
2227
}
2232
2228
2233
2229
fn sidebar_trait ( cx : & Context < ' _ > , buf : & mut Buffer , it : & clean:: Item , t : & clean:: Trait ) {
@@ -2236,101 +2232,125 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
2236
2232
fn print_sidebar_section (
2237
2233
out : & mut Buffer ,
2238
2234
items : & [ clean:: Item ] ,
2239
- before : & str ,
2235
+ title : & str ,
2236
+ id : & str ,
2240
2237
filter : impl Fn ( & clean:: Item ) -> bool ,
2241
2238
write : impl Fn ( & mut Buffer , & str ) ,
2242
- after : & str ,
2243
2239
) {
2244
- let mut items = items
2245
- . iter ( )
2246
- . filter_map ( |m| match m. name {
2247
- Some ( ref name) if filter ( m) => Some ( name. as_str ( ) ) ,
2248
- _ => None ,
2249
- } )
2250
- . collect :: < Vec < _ > > ( ) ;
2240
+ print_sidebar_section_with (
2241
+ out,
2242
+ title,
2243
+ id,
2244
+ items. iter ( ) . filter ( |i| filter ( i) ) . filter_map ( |i| i. name . map ( |n| n. as_str ( ) ) ) ,
2245
+ |buf, s| write ( buf, & s) ,
2246
+ )
2247
+ }
2248
+
2249
+ fn print_sidebar_section_with < T : Ord > (
2250
+ out : & mut Buffer ,
2251
+ title : & str ,
2252
+ id : & str ,
2253
+ iter : impl Iterator < Item = T > ,
2254
+ write : impl Fn ( & mut Buffer , T ) ,
2255
+ ) {
2256
+ let mut items = iter. collect :: < Vec < _ > > ( ) ;
2251
2257
2252
2258
if !items. is_empty ( ) {
2253
2259
items. sort_unstable ( ) ;
2254
- out. push_str ( before) ;
2260
+ write ! (
2261
+ out,
2262
+ "<h3 class=\" sidebar-title\" ><a href=\" #{}\" >\
2263
+ {}</a></h3><div class=\" sidebar-links\" >",
2264
+ id, title
2265
+ ) ;
2255
2266
for item in items. into_iter ( ) {
2256
- write ( out, & item) ;
2267
+ write ( out, item) ;
2257
2268
}
2258
- out. push_str ( after ) ;
2269
+ out. push_str ( "</div>" ) ;
2259
2270
}
2260
2271
}
2261
2272
2262
2273
print_sidebar_section (
2263
2274
buf,
2264
2275
& t. items ,
2265
- "<h3 class= \" sidebar-title \" ><a href= \" #associated-types \" > \
2266
- Associated Types</a></h3><div class= \" sidebar-links \" > ",
2276
+ "Associated Types" ,
2277
+ "associated-types ",
2267
2278
|m| m. is_associated_type ( ) ,
2268
2279
|out, sym| write ! ( out, "<a href=\" #associatedtype.{0}\" >{0}</a>" , sym) ,
2269
- "</div>" ,
2270
2280
) ;
2271
2281
2272
2282
print_sidebar_section (
2273
2283
buf,
2274
2284
& t. items ,
2275
- "<h3 class= \" sidebar-title \" ><a href= \" #associated-const \" > \
2276
- Associated Constants</a></h3><div class= \" sidebar-links \" > ",
2285
+ "Associated Constants" ,
2286
+ "associated-const ",
2277
2287
|m| m. is_associated_const ( ) ,
2278
2288
|out, sym| write ! ( out, "<a href=\" #associatedconstant.{0}\" >{0}</a>" , sym) ,
2279
- "</div>" ,
2280
2289
) ;
2281
2290
2282
2291
print_sidebar_section (
2283
2292
buf,
2284
2293
& t. items ,
2285
- "<h3 class= \" sidebar-title \" ><a href= \" #required-methods \" > \
2286
- Required Methods</a></h3><div class= \" sidebar-links \" > ",
2294
+ "Required Methods" ,
2295
+ "required-methods ",
2287
2296
|m| m. is_ty_method ( ) ,
2288
2297
|out, sym| write ! ( out, "<a href=\" #tymethod.{0}\" >{0}</a>" , sym) ,
2289
- "</div>" ,
2290
2298
) ;
2291
2299
2292
2300
print_sidebar_section (
2293
2301
buf,
2294
2302
& t. items ,
2295
- "<h3 class= \" sidebar-title \" ><a href= \" #provided-methods \" > \
2296
- Provided Methods</a></h3><div class= \" sidebar-links \" > ",
2303
+ "Provided Methods" ,
2304
+ "provided-methods ",
2297
2305
|m| m. is_method ( ) ,
2298
2306
|out, sym| write ! ( out, "<a href=\" #method.{0}\" >{0}</a>" , sym) ,
2299
- "</div>" ,
2300
2307
) ;
2301
2308
2302
2309
let cache = cx. cache ( ) ;
2303
- if let Some ( implementors) = cache. implementors . get ( & it. def_id . expect_def_id ( ) ) {
2304
- let mut res = implementors
2305
- . iter ( )
2306
- . filter ( |i| {
2307
- i. inner_impl ( ) . for_ . def_id ( cache) . map_or ( false , |d| !cache. paths . contains_key ( & d) )
2308
- } )
2309
- . filter_map ( |i| extract_for_impl_name ( & i. impl_item , cx) )
2310
- . collect :: < Vec < _ > > ( ) ;
2311
-
2312
- if !res. is_empty ( ) {
2313
- res. sort ( ) ;
2314
- buf. push_str (
2315
- "<h3 class=\" sidebar-title\" ><a href=\" #foreign-impls\" >\
2316
- Implementations on Foreign Types</a></h3>\
2317
- <div class=\" sidebar-links\" >",
2318
- ) ;
2319
- for ( name, id) in res. into_iter ( ) {
2320
- write ! ( buf, "<a href=\" #{}\" >{}</a>" , id, Escape ( & name) ) ;
2321
- }
2322
- buf. push_str ( "</div>" ) ;
2323
- }
2324
- }
2310
+ let did = it. def_id . expect_def_id ( ) ;
2311
+
2312
+ let ( local_impl, foreign_impls) = cache
2313
+ . implementors
2314
+ . get ( & did)
2315
+ . iter ( )
2316
+ . flat_map ( |x| * x)
2317
+ . partition :: < Vec < _ > , _ > ( |i| i. is_local ( cache) ) ;
2318
+
2319
+ print_sidebar_section_with (
2320
+ buf,
2321
+ "Implementations on Foreign Types" ,
2322
+ "foreign-impls" ,
2323
+ foreign_impls. iter ( ) . map ( |i| extract_for_impl_name ( i, cx) ) ,
2324
+ |buf, ( name, id) | write ! ( buf, "<a href=\" #{}\" >{}</a>" , id, Escape ( & name) ) ,
2325
+ ) ;
2325
2326
2326
2327
sidebar_assoc_items ( cx, buf, it) ;
2327
2328
2328
- buf. push_str ( "<h3 class=\" sidebar-title\" ><a href=\" #implementors\" >Implementors</a></h3>" ) ;
2329
+ print_sidebar_section_with (
2330
+ buf,
2331
+ "Implementors" ,
2332
+ "implementors" ,
2333
+ local_impl. iter ( ) . filter ( |i| i. inner_impl ( ) . polarity == ty:: ImplPolarity :: Positive ) . map (
2334
+ |i| {
2335
+ (
2336
+ format ! ( "{:#}" , i. inner_impl( ) . for_. print( cx) ) ,
2337
+ cx. item_to_html_id_map
2338
+ . borrow ( )
2339
+ . get ( & i. impl_item . def_id )
2340
+ . unwrap_or_else ( || panic ! ( "Not in index {:#?}" , i) )
2341
+ . clone ( ) ,
2342
+ )
2343
+ } ,
2344
+ ) ,
2345
+ |buf, ( name, id) | write ! ( buf, "<a href=\" #{}\" >{}</a>" , id, Escape ( & name) ) ,
2346
+ ) ;
2347
+
2329
2348
if t. is_auto {
2330
2349
buf. push_str (
2331
2350
"<h3 class=\" sidebar-title\" ><a \
2332
2351
href=\" #synthetic-implementors\" >Auto Implementors</a></h3>",
2333
2352
) ;
2353
+ // FIXME: List Auto Implementors
2334
2354
}
2335
2355
2336
2356
buf. push_str ( "</div>" )
0 commit comments