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