@@ -372,23 +372,19 @@ pub fn reset_ids() {
372
372
USED_ID_MAP . with ( |s| * s. borrow_mut ( ) = init_ids ( ) ) ;
373
373
}
374
374
375
- pub fn with_unique_id < T , F : FnOnce ( & str ) -> T > ( candidate : String , f : F ) -> T {
375
+ pub fn derive_id ( candidate : String ) -> String {
376
376
USED_ID_MAP . with ( |map| {
377
- let ( id, ret) = match map. borrow_mut ( ) . get_mut ( & candidate) {
378
- None => {
379
- let ret = f ( & candidate) ;
380
- ( candidate, ret)
381
- } ,
377
+ let id = match map. borrow_mut ( ) . get_mut ( & candidate) {
378
+ None => candidate,
382
379
Some ( a) => {
383
380
let id = format ! ( "{}-{}" , candidate, * a) ;
384
- let ret = f ( & id) ;
385
381
* a += 1 ;
386
- ( id , ret )
382
+ id
387
383
}
388
384
} ;
389
385
390
- map. borrow_mut ( ) . insert ( id, 1 ) ;
391
- ret
386
+ map. borrow_mut ( ) . insert ( id. clone ( ) , 1 ) ;
387
+ id
392
388
} )
393
389
}
394
390
@@ -1745,10 +1741,9 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1745
1741
ItemType :: AssociatedType => ( "associated-types" , "Associated Types" ) ,
1746
1742
ItemType :: AssociatedConst => ( "associated-consts" , "Associated Constants" ) ,
1747
1743
} ;
1748
- try!( with_unique_id ( short. to_owned ( ) , |id|
1749
- write ! ( w, "<h2 id='{id}' class='section-header'>\
1750
- <a href=\" #{id}\" >{name}</a></h2>\n <table>",
1751
- id = id, name = name) ) ) ;
1744
+ try!( write ! ( w, "<h2 id='{id}' class='section-header'>\
1745
+ <a href=\" #{id}\" >{name}</a></h2>\n <table>",
1746
+ id = derive_id( short. to_owned( ) ) , name = name) ) ;
1752
1747
}
1753
1748
1754
1749
match myitem. inner {
@@ -1970,10 +1965,10 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
1970
1965
fn trait_item ( w : & mut fmt:: Formatter , cx : & Context , m : & clean:: Item )
1971
1966
-> fmt:: Result {
1972
1967
let name = m. name . as_ref ( ) . unwrap ( ) ;
1973
- try! ( with_unique_id ( format ! ( "{}.{}" , shortty( m) , name) , |id|
1974
- write ! ( w, "<h3 id='{id}' class='method stab {stab}'><code>" ,
1968
+ let id = derive_id ( format ! ( "{}.{}" , shortty( m) , name) ) ;
1969
+ try! ( write ! ( w, "<h3 id='{id}' class='method stab {stab}'><code>" ,
1975
1970
id = id,
1976
- stab = m. stability_class( ) ) ) ) ;
1971
+ stab = m. stability_class( ) ) ) ;
1977
1972
try!( render_assoc_item ( w, m, AssocItemLink :: Anchor ) ) ;
1978
1973
try!( write ! ( w, "</code></h3>" ) ) ;
1979
1974
try!( document ( w, cx, m) ) ;
@@ -2162,12 +2157,11 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2162
2157
if fields. peek ( ) . is_some ( ) {
2163
2158
try!( write ! ( w, "<h2 class='fields'>Fields</h2>\n <table>" ) ) ;
2164
2159
for field in fields {
2165
- let name = field. name . as_ref ( ) . unwrap ( ) ;
2166
- try!( with_unique_id ( format ! ( "structfield.{}" , name) , |id|
2167
- write ! ( w, "<tr class='stab {}'><td id='{}'><code>{}</code></td><td>" ,
2168
- field. stability_class( ) ,
2169
- id,
2170
- name) ) ) ;
2160
+ try!( write ! ( w, "<tr class='stab {stab}'>
2161
+ <td id='structfield.{name}'>\
2162
+ <code>{name}</code></td><td>",
2163
+ stab = field. stability_class( ) ,
2164
+ name = field. name. as_ref( ) . unwrap( ) ) ) ;
2171
2165
try!( document ( w, cx, field) ) ;
2172
2166
try!( write ! ( w, "</td></tr>" ) ) ;
2173
2167
}
@@ -2234,9 +2228,8 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2234
2228
if !e. variants . is_empty ( ) {
2235
2229
try!( write ! ( w, "<h2 class='variants'>Variants</h2>\n <table>" ) ) ;
2236
2230
for variant in & e. variants {
2237
- let name = variant. name . as_ref ( ) . unwrap ( ) ;
2238
- try!( with_unique_id ( format ! ( "variant.{}" , name) , |id|
2239
- write ! ( w, "<tr><td id='{}'><code>{}</code></td><td>" , id, name) ) ) ;
2231
+ try!( write ! ( w, "<tr><td id='variant.{name}'><code>{name}</code></td><td>" ,
2232
+ name = variant. name. as_ref( ) . unwrap( ) ) ) ;
2240
2233
try!( document ( w, cx, variant) ) ;
2241
2234
match variant. inner {
2242
2235
clean:: VariantItem ( ref var) => {
@@ -2254,10 +2247,11 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2254
2247
try!( write ! ( w, "<h3 class='fields'>Fields</h3>\n
2255
2248
<table>" ) ) ;
2256
2249
for field in fields {
2257
- let v = variant. name . as_ref ( ) . unwrap ( ) ;
2258
- let f = field. name . as_ref ( ) . unwrap ( ) ;
2259
- try!( with_unique_id ( format ! ( "variant.{}.field.{}" , v, f) , |id|
2260
- write ! ( w, "<tr><td id='{}'><code>{}</code></td><td>" , id, f) ) ) ;
2250
+ try!( write ! ( w, "<tr><td \
2251
+ id='variant.{v}.field.{f}'>\
2252
+ <code>{f}</code></td><td>",
2253
+ v = variant. name. as_ref( ) . unwrap( ) ,
2254
+ f = field. name. as_ref( ) . unwrap( ) ) ) ;
2261
2255
try!( document ( w, cx, field) ) ;
2262
2256
try!( write ! ( w, "</td></tr>" ) ) ;
2263
2257
}
@@ -2474,33 +2468,33 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2474
2468
clean:: MethodItem ( ..) | clean:: TyMethodItem ( ..) => {
2475
2469
// Only render when the method is not static or we allow static methods
2476
2470
if !is_static_method ( item) || render_static {
2477
- try! ( with_unique_id ( format ! ( "method.{}" , name) , |id|
2478
- write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty( item) ) ) ) ;
2471
+ let id = derive_id ( format ! ( "method.{}" , name) ) ;
2472
+ try! ( write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty( item) ) ) ;
2479
2473
try!( render_assoc_item ( w, item, link) ) ;
2480
2474
try!( write ! ( w, "</code></h4>\n " ) ) ;
2481
2475
}
2482
2476
}
2483
2477
clean:: TypedefItem ( ref tydef, _) => {
2484
- try! ( with_unique_id ( format ! ( "assoc_type.{}" , name) , |id|
2485
- write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty( item) ) ) ) ;
2478
+ let id = derive_id ( format ! ( "assoc_type.{}" , name) ) ;
2479
+ try! ( write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty( item) ) ) ;
2486
2480
try!( write ! ( w, "type {} = {}" , name, tydef. type_) ) ;
2487
2481
try!( write ! ( w, "</code></h4>\n " ) ) ;
2488
2482
}
2489
2483
clean:: AssociatedConstItem ( ref ty, ref default) => {
2490
- try! ( with_unique_id ( format ! ( "assoc_const.{}" , name) , |id|
2491
- write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty( item) ) ) ) ;
2484
+ let id = derive_id ( format ! ( "assoc_const.{}" , name) ) ;
2485
+ try! ( write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty( item) ) ) ;
2492
2486
try!( assoc_const ( w, item, ty, default. as_ref ( ) ) ) ;
2493
2487
try!( write ! ( w, "</code></h4>\n " ) ) ;
2494
2488
}
2495
2489
clean:: ConstantItem ( ref c) => {
2496
- try! ( with_unique_id ( format ! ( "assoc_const.{}" , name) , |id|
2497
- write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty( item) ) ) ) ;
2490
+ let id = derive_id ( format ! ( "assoc_const.{}" , name) ) ;
2491
+ try! ( write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty( item) ) ) ;
2498
2492
try!( assoc_const ( w, item, & c. type_ , Some ( & c. expr ) ) ) ;
2499
2493
try!( write ! ( w, "</code></h4>\n " ) ) ;
2500
2494
}
2501
2495
clean:: AssociatedTypeItem ( ref bounds, ref default) => {
2502
- try! ( with_unique_id ( format ! ( "assoc_type.{}" , name) , |id|
2503
- write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty( item) ) ) ) ;
2496
+ let id = derive_id ( format ! ( "assoc_type.{}" , name) ) ;
2497
+ try! ( write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty( item) ) ) ;
2504
2498
try!( assoc_type ( w, item, bounds, default) ) ;
2505
2499
try!( write ! ( w, "</code></h4>\n " ) ) ;
2506
2500
}
0 commit comments