@@ -62,7 +62,7 @@ use rustc::middle::stability;
62
62
use rustc:: session:: config:: get_unstable_features_setting;
63
63
use rustc_front:: hir;
64
64
65
- use clean:: { self , SelfTy , Attributes } ;
65
+ use clean:: { self , SelfTy , Attributes , GetDefId } ;
66
66
use doctree;
67
67
use fold:: DocFolder ;
68
68
use html:: escape:: Escape ;
@@ -144,9 +144,7 @@ pub struct Impl {
144
144
145
145
impl Impl {
146
146
fn trait_did ( & self ) -> Option < DefId > {
147
- self . impl_ . trait_ . as_ref ( ) . and_then ( |tr| {
148
- if let clean:: ResolvedPath { did, .. } = * tr { Some ( did) } else { None }
149
- } )
147
+ self . impl_ . trait_ . def_id ( )
150
148
}
151
149
}
152
150
@@ -967,7 +965,7 @@ impl DocFolder for Cache {
967
965
968
966
// Collect all the implementors of traits.
969
967
if let clean:: ImplItem ( ref i) = item. inner {
970
- if let Some ( clean :: ResolvedPath { did, .. } ) = i. trait_ {
968
+ if let Some ( did) = i. trait_ . def_id ( ) {
971
969
self . implementors . entry ( did) . or_insert ( vec ! [ ] ) . push ( Implementor {
972
970
def_id : item. def_id ,
973
971
stability : item. stability . clone ( ) ,
@@ -2066,10 +2064,11 @@ fn render_stability_since(w: &mut fmt::Formatter,
2066
2064
render_stability_since_raw ( w, item. stable_since ( ) , containing_item. stable_since ( ) )
2067
2065
}
2068
2066
2069
- fn render_assoc_item ( w : & mut fmt:: Formatter , meth : & clean:: Item ,
2067
+ fn render_assoc_item ( w : & mut fmt:: Formatter ,
2068
+ item : & clean:: Item ,
2070
2069
link : AssocItemLink ) -> fmt:: Result {
2071
2070
fn method ( w : & mut fmt:: Formatter ,
2072
- it : & clean:: Item ,
2071
+ meth : & clean:: Item ,
2073
2072
unsafety : hir:: Unsafety ,
2074
2073
constness : hir:: Constness ,
2075
2074
abi : abi:: Abi ,
@@ -2080,12 +2079,20 @@ fn render_assoc_item(w: &mut fmt::Formatter, meth: &clean::Item,
2080
2079
-> fmt:: Result {
2081
2080
use syntax:: abi:: Abi ;
2082
2081
2083
- let name = it . name . as_ref ( ) . unwrap ( ) ;
2084
- let anchor = format ! ( "#{}.{}" , shortty( it ) , name) ;
2082
+ let name = meth . name . as_ref ( ) . unwrap ( ) ;
2083
+ let anchor = format ! ( "#{}.{}" , shortty( meth ) , name) ;
2085
2084
let href = match link {
2086
2085
AssocItemLink :: Anchor => anchor,
2087
- AssocItemLink :: GotoSource ( did) => {
2088
- href ( did) . map ( |p| format ! ( "{}{}" , p. 0 , anchor) ) . unwrap_or ( anchor)
2086
+ AssocItemLink :: GotoSource ( did, provided_methods) => {
2087
+ // We're creating a link from an impl-item to the corresponding
2088
+ // trait-item and need to map the anchored type accordingly.
2089
+ let ty = if provided_methods. contains ( name) {
2090
+ ItemType :: Method
2091
+ } else {
2092
+ ItemType :: TyMethod
2093
+ } ;
2094
+
2095
+ href ( did) . map ( |p| format ! ( "{}#{}.{}" , p. 0 , ty, name) ) . unwrap_or ( anchor)
2089
2096
}
2090
2097
} ;
2091
2098
let vis_constness = match get_unstable_features_setting ( ) {
@@ -2106,21 +2113,21 @@ fn render_assoc_item(w: &mut fmt::Formatter, meth: &clean::Item,
2106
2113
decl = Method ( selfty, d) ,
2107
2114
where_clause = WhereClause ( g) )
2108
2115
}
2109
- match meth . inner {
2116
+ match item . inner {
2110
2117
clean:: TyMethodItem ( ref m) => {
2111
- method ( w, meth , m. unsafety , hir:: Constness :: NotConst ,
2118
+ method ( w, item , m. unsafety , hir:: Constness :: NotConst ,
2112
2119
m. abi , & m. generics , & m. self_ , & m. decl , link)
2113
2120
}
2114
2121
clean:: MethodItem ( ref m) => {
2115
- method ( w, meth , m. unsafety , m. constness ,
2122
+ method ( w, item , m. unsafety , m. constness ,
2116
2123
m. abi , & m. generics , & m. self_ , & m. decl ,
2117
2124
link)
2118
2125
}
2119
2126
clean:: AssociatedConstItem ( ref ty, ref default) => {
2120
- assoc_const ( w, meth , ty, default. as_ref ( ) )
2127
+ assoc_const ( w, item , ty, default. as_ref ( ) )
2121
2128
}
2122
2129
clean:: AssociatedTypeItem ( ref bounds, ref default) => {
2123
- assoc_type ( w, meth , bounds, default)
2130
+ assoc_type ( w, item , bounds, default)
2124
2131
}
2125
2132
_ => panic ! ( "render_assoc_item called on non-associated-item" )
2126
2133
}
@@ -2338,9 +2345,9 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
2338
2345
}
2339
2346
2340
2347
#[ derive( Copy , Clone ) ]
2341
- enum AssocItemLink {
2348
+ enum AssocItemLink < ' a > {
2342
2349
Anchor ,
2343
- GotoSource ( DefId ) ,
2350
+ GotoSource ( DefId , & ' a HashSet < String > ) ,
2344
2351
}
2345
2352
2346
2353
enum AssocItemRender < ' a > {
@@ -2383,12 +2390,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
2383
2390
}
2384
2391
if !traits. is_empty ( ) {
2385
2392
let deref_impl = traits. iter ( ) . find ( |t| {
2386
- match * t. impl_ . trait_ . as_ref ( ) . unwrap ( ) {
2387
- clean:: ResolvedPath { did, .. } => {
2388
- Some ( did) == c. deref_trait_did
2389
- }
2390
- _ => false
2391
- }
2393
+ t. impl_ . trait_ . def_id ( ) == c. deref_trait_did
2392
2394
} ) ;
2393
2395
if let Some ( impl_) = deref_impl {
2394
2396
render_deref_methods ( w, cx, impl_, containing_item) ?;
@@ -2400,17 +2402,17 @@ fn render_assoc_items(w: &mut fmt::Formatter,
2400
2402
} ) ;
2401
2403
for i in & manual {
2402
2404
let did = i. trait_did ( ) . unwrap ( ) ;
2403
- render_impl ( w , cx , i , AssocItemLink :: GotoSource ( did) , true ,
2404
- containing_item. stable_since ( ) ) ?;
2405
+ let assoc_link = AssocItemLink :: GotoSource ( did, & i . impl_ . provided_trait_methods ) ;
2406
+ render_impl ( w , cx , i , assoc_link , true , containing_item. stable_since ( ) ) ?;
2405
2407
}
2406
2408
if !derived. is_empty ( ) {
2407
2409
write ! ( w, "<h3 id='derived_implementations'>\
2408
2410
Derived Implementations \
2409
2411
</h3>") ?;
2410
2412
for i in & derived {
2411
2413
let did = i. trait_did ( ) . unwrap ( ) ;
2412
- render_impl ( w , cx , i , AssocItemLink :: GotoSource ( did) , true ,
2413
- containing_item. stable_since ( ) ) ?;
2414
+ let assoc_link = AssocItemLink :: GotoSource ( did, & i . impl_ . provided_trait_methods ) ;
2415
+ render_impl ( w , cx , i , assoc_link , true , containing_item. stable_since ( ) ) ?;
2414
2416
}
2415
2417
}
2416
2418
}
@@ -2427,17 +2429,16 @@ fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl,
2427
2429
}
2428
2430
} ) . next ( ) . expect ( "Expected associated type binding" ) ;
2429
2431
let what = AssocItemRender :: DerefFor { trait_ : deref_type, type_ : target } ;
2430
- match * target {
2431
- clean:: ResolvedPath { did, .. } => render_assoc_items ( w, cx, container_item, did, what) ,
2432
- _ => {
2433
- if let Some ( prim) = target. primitive_type ( ) {
2434
- if let Some ( c) = cache ( ) . primitive_locations . get ( & prim) {
2435
- let did = DefId { krate : * c, index : prim. to_def_index ( ) } ;
2436
- render_assoc_items ( w, cx, container_item, did, what) ?;
2437
- }
2432
+ if let Some ( did) = target. def_id ( ) {
2433
+ render_assoc_items ( w, cx, container_item, did, what)
2434
+ } else {
2435
+ if let Some ( prim) = target. primitive_type ( ) {
2436
+ if let Some ( c) = cache ( ) . primitive_locations . get ( & prim) {
2437
+ let did = DefId { krate : * c, index : prim. to_def_index ( ) } ;
2438
+ render_assoc_items ( w, cx, container_item, did, what) ?;
2438
2439
}
2439
- Ok ( ( ) )
2440
2440
}
2441
+ Ok ( ( ) )
2441
2442
}
2442
2443
}
2443
2444
@@ -2521,18 +2522,19 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2521
2522
2522
2523
fn render_default_items ( w : & mut fmt:: Formatter ,
2523
2524
cx : & Context ,
2524
- did : DefId ,
2525
2525
t : & clean:: Trait ,
2526
- i : & clean:: Impl ,
2527
- render_static : bool ,
2528
- outer_version : Option < & str > ) -> fmt:: Result {
2526
+ i : & clean:: Impl ,
2527
+ render_static : bool ,
2528
+ outer_version : Option < & str > ) -> fmt:: Result {
2529
2529
for trait_item in & t. items {
2530
2530
let n = trait_item. name . clone ( ) ;
2531
- if i. items . iter ( ) . find ( |m| { m. name == n } ) . is_some ( ) {
2531
+ if i. items . iter ( ) . find ( |m| m. name == n) . is_some ( ) {
2532
2532
continue ;
2533
2533
}
2534
+ let did = i. trait_ . as_ref ( ) . unwrap ( ) . def_id ( ) . unwrap ( ) ;
2535
+ let assoc_link = AssocItemLink :: GotoSource ( did, & i. provided_trait_methods ) ;
2534
2536
2535
- doctraititem ( w, cx, trait_item, AssocItemLink :: GotoSource ( did ) , render_static,
2537
+ doctraititem ( w, cx, trait_item, assoc_link , render_static,
2536
2538
outer_version) ?;
2537
2539
}
2538
2540
Ok ( ( ) )
@@ -2542,9 +2544,9 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2542
2544
// default methods which weren't overridden in the implementation block.
2543
2545
// FIXME: this also needs to be done for associated types, whenever defaults
2544
2546
// for them work.
2545
- if let Some ( clean :: ResolvedPath { did, .. } ) = i. impl_ . trait_ {
2547
+ if let Some ( did) = i. trait_did ( ) {
2546
2548
if let Some ( t) = cache ( ) . traits . get ( & did) {
2547
- render_default_items ( w, cx, did , t, & i. impl_ , render_header, outer_version) ?;
2549
+ render_default_items ( w, cx, t, & i. impl_ , render_header, outer_version) ?;
2548
2550
}
2549
2551
}
2550
2552
write ! ( w, "</div>" ) ?;
0 commit comments