@@ -1903,34 +1903,35 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
1903
1903
if t. items . is_empty ( ) {
1904
1904
write ! ( w, "{{ }}" ) ?;
1905
1905
} else {
1906
+ // FIXME: we should be using a derived_id for the Anchors here
1906
1907
write ! ( w, "{{\n " ) ?;
1907
1908
for t in & types {
1908
1909
write ! ( w, " " ) ?;
1909
- render_assoc_item ( w, t, AssocItemLink :: Anchor ) ?;
1910
+ render_assoc_item ( w, t, AssocItemLink :: Anchor ( None ) ) ?;
1910
1911
write ! ( w, ";\n " ) ?;
1911
1912
}
1912
1913
if !types. is_empty ( ) && !consts. is_empty ( ) {
1913
1914
w. write_str ( "\n " ) ?;
1914
1915
}
1915
1916
for t in & consts {
1916
1917
write ! ( w, " " ) ?;
1917
- render_assoc_item ( w, t, AssocItemLink :: Anchor ) ?;
1918
+ render_assoc_item ( w, t, AssocItemLink :: Anchor ( None ) ) ?;
1918
1919
write ! ( w, ";\n " ) ?;
1919
1920
}
1920
1921
if !consts. is_empty ( ) && !required. is_empty ( ) {
1921
1922
w. write_str ( "\n " ) ?;
1922
1923
}
1923
1924
for m in & required {
1924
1925
write ! ( w, " " ) ?;
1925
- render_assoc_item ( w, m, AssocItemLink :: Anchor ) ?;
1926
+ render_assoc_item ( w, m, AssocItemLink :: Anchor ( None ) ) ?;
1926
1927
write ! ( w, ";\n " ) ?;
1927
1928
}
1928
1929
if !required. is_empty ( ) && !provided. is_empty ( ) {
1929
1930
w. write_str ( "\n " ) ?;
1930
1931
}
1931
1932
for m in & provided {
1932
1933
write ! ( w, " " ) ?;
1933
- render_assoc_item ( w, m, AssocItemLink :: Anchor ) ?;
1934
+ render_assoc_item ( w, m, AssocItemLink :: Anchor ( None ) ) ?;
1934
1935
write ! ( w, " {{ ... }}\n " ) ?;
1935
1936
}
1936
1937
write ! ( w, "}}" ) ?;
@@ -1947,7 +1948,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
1947
1948
write ! ( w, "<h3 id='{id}' class='method stab {stab}'><code>" ,
1948
1949
id = id,
1949
1950
stab = m. stability_class( ) ) ?;
1950
- render_assoc_item ( w, m, AssocItemLink :: Anchor ) ?;
1951
+ render_assoc_item ( w, m, AssocItemLink :: Anchor ( Some ( & id ) ) ) ?;
1951
1952
write ! ( w, "</code>" ) ?;
1952
1953
render_stability_since ( w, m, t) ?;
1953
1954
write ! ( w, "</h3>" ) ?;
@@ -2042,7 +2043,8 @@ fn naive_assoc_href(it: &clean::Item, link: AssocItemLink) -> String {
2042
2043
2043
2044
let anchor = format ! ( "#{}.{}" , ty, name) ;
2044
2045
match link {
2045
- AssocItemLink :: Anchor => anchor,
2046
+ AssocItemLink :: Anchor ( Some ( ref id) ) => format ! ( "#{}" , id) ,
2047
+ AssocItemLink :: Anchor ( None ) => anchor,
2046
2048
AssocItemLink :: GotoSource ( did, _) => {
2047
2049
href ( did) . map ( |p| format ! ( "{}{}" , p. 0 , anchor) ) . unwrap_or ( anchor)
2048
2050
}
@@ -2117,7 +2119,8 @@ fn render_assoc_item(w: &mut fmt::Formatter,
2117
2119
let name = meth. name . as_ref ( ) . unwrap ( ) ;
2118
2120
let anchor = format ! ( "#{}.{}" , shortty( meth) , name) ;
2119
2121
let href = match link {
2120
- AssocItemLink :: Anchor => anchor,
2122
+ AssocItemLink :: Anchor ( Some ( ref id) ) => format ! ( "#{}" , id) ,
2123
+ AssocItemLink :: Anchor ( None ) => anchor,
2121
2124
AssocItemLink :: GotoSource ( did, provided_methods) => {
2122
2125
// We're creating a link from an impl-item to the corresponding
2123
2126
// trait-item and need to map the anchored type accordingly.
@@ -2378,10 +2381,19 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
2378
2381
2379
2382
#[ derive( Copy , Clone ) ]
2380
2383
enum AssocItemLink < ' a > {
2381
- Anchor ,
2384
+ Anchor ( Option < & ' a str > ) ,
2382
2385
GotoSource ( DefId , & ' a HashSet < String > ) ,
2383
2386
}
2384
2387
2388
+ impl < ' a > AssocItemLink < ' a > {
2389
+ fn anchor ( & self , id : & ' a String ) -> Self {
2390
+ match * self {
2391
+ AssocItemLink :: Anchor ( _) => { AssocItemLink :: Anchor ( Some ( & id) ) } ,
2392
+ ref other => * other,
2393
+ }
2394
+ }
2395
+ }
2396
+
2385
2397
enum AssocItemRender < ' a > {
2386
2398
All ,
2387
2399
DerefFor { trait_ : & ' a clean:: Type , type_ : & ' a clean:: Type } ,
@@ -2413,7 +2425,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
2413
2425
}
2414
2426
} ;
2415
2427
for i in & non_trait {
2416
- render_impl ( w, cx, i, AssocItemLink :: Anchor , render_header,
2428
+ render_impl ( w, cx, i, AssocItemLink :: Anchor ( None ) , render_header,
2417
2429
containing_item. stable_since ( ) ) ?;
2418
2430
}
2419
2431
}
@@ -2509,32 +2521,32 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2509
2521
write ! ( w, "<h4 id='{}' class='{}'>" , id, shortty) ?;
2510
2522
render_stability_since_raw ( w, item. stable_since ( ) , outer_version) ?;
2511
2523
write ! ( w, "<code>" ) ?;
2512
- render_assoc_item ( w, item, link) ?;
2524
+ render_assoc_item ( w, item, link. anchor ( & id ) ) ?;
2513
2525
write ! ( w, "</code></h4>\n " ) ?;
2514
2526
}
2515
2527
}
2516
2528
clean:: TypedefItem ( ref tydef, _) => {
2517
2529
let id = derive_id ( format ! ( "{}.{}" , ItemType :: AssociatedType , name) ) ;
2518
2530
write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty) ?;
2519
- assoc_type ( w, item, & Vec :: new ( ) , Some ( & tydef. type_ ) , link) ?;
2531
+ assoc_type ( w, item, & Vec :: new ( ) , Some ( & tydef. type_ ) , link. anchor ( & id ) ) ?;
2520
2532
write ! ( w, "</code></h4>\n " ) ?;
2521
2533
}
2522
2534
clean:: AssociatedConstItem ( ref ty, ref default) => {
2523
2535
let id = derive_id ( format ! ( "{}.{}" , shortty, name) ) ;
2524
2536
write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty) ?;
2525
- assoc_const ( w, item, ty, default. as_ref ( ) , link) ?;
2537
+ assoc_const ( w, item, ty, default. as_ref ( ) , link. anchor ( & id ) ) ?;
2526
2538
write ! ( w, "</code></h4>\n " ) ?;
2527
2539
}
2528
2540
clean:: ConstantItem ( ref c) => {
2529
2541
let id = derive_id ( format ! ( "{}.{}" , shortty, name) ) ;
2530
2542
write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty) ?;
2531
- assoc_const ( w, item, & c. type_ , Some ( & c. expr ) , link) ?;
2543
+ assoc_const ( w, item, & c. type_ , Some ( & c. expr ) , link. anchor ( & id ) ) ?;
2532
2544
write ! ( w, "</code></h4>\n " ) ?;
2533
2545
}
2534
2546
clean:: AssociatedTypeItem ( ref bounds, ref default) => {
2535
2547
let id = derive_id ( format ! ( "{}.{}" , shortty, name) ) ;
2536
2548
write ! ( w, "<h4 id='{}' class='{}'><code>" , id, shortty) ?;
2537
- assoc_type ( w, item, bounds, default. as_ref ( ) , link) ?;
2549
+ assoc_type ( w, item, bounds, default. as_ref ( ) , link. anchor ( & id ) ) ?;
2538
2550
write ! ( w, "</code></h4>\n " ) ?;
2539
2551
}
2540
2552
clean:: StrippedItem ( ..) => return Ok ( ( ) ) ,
0 commit comments