@@ -145,14 +145,19 @@ pub struct Implementor {
145
145
/// Metadata about implementations for a type.
146
146
#[ derive( Clone ) ]
147
147
pub struct Impl {
148
- pub impl_ : clean:: Impl ,
149
- pub dox : Option < String > ,
150
- pub stability : Option < clean:: Stability > ,
148
+ pub impl_item : clean:: Item ,
151
149
}
152
150
153
151
impl Impl {
152
+ fn inner_impl ( & self ) -> & clean:: Impl {
153
+ match self . impl_item . inner {
154
+ clean:: ImplItem ( ref impl_) => impl_,
155
+ _ => panic ! ( "non-impl item found in impl" )
156
+ }
157
+ }
158
+
154
159
fn trait_did ( & self ) -> Option < DefId > {
155
- self . impl_ . trait_ . def_id ( )
160
+ self . inner_impl ( ) . trait_ . def_id ( )
156
161
}
157
162
}
158
163
@@ -1189,31 +1194,34 @@ impl DocFolder for Cache {
1189
1194
// Once we've recursively found all the generics, then hoard off all the
1190
1195
// implementations elsewhere
1191
1196
let ret = self . fold_item_recur ( item) . and_then ( |item| {
1192
- if let clean:: Item { attrs , inner : clean:: ImplItem ( i ) , .. } = item {
1197
+ if let clean:: Item { inner : clean:: ImplItem ( _ ) , .. } = item {
1193
1198
// Figure out the id of this impl. This may map to a
1194
1199
// primitive rather than always to a struct/enum.
1195
- let did = match i. for_ {
1196
- clean:: ResolvedPath { did, .. } |
1197
- clean:: BorrowedRef {
1198
- type_ : box clean:: ResolvedPath { did, .. } , ..
1199
- } => {
1200
- Some ( did)
1201
- }
1202
- ref t => {
1203
- t. primitive_type ( ) . and_then ( |t| {
1204
- self . primitive_locations . get ( & t) . map ( |n| {
1205
- let id = t. to_def_index ( ) ;
1206
- DefId { krate : * n, index : id }
1200
+ // Note: matching twice to restrict the lifetime of the `i` borrow.
1201
+ let did = if let clean:: Item { inner : clean:: ImplItem ( ref i) , .. } = item {
1202
+ match i. for_ {
1203
+ clean:: ResolvedPath { did, .. } |
1204
+ clean:: BorrowedRef {
1205
+ type_ : box clean:: ResolvedPath { did, .. } , ..
1206
+ } => {
1207
+ Some ( did)
1208
+ }
1209
+ ref t => {
1210
+ t. primitive_type ( ) . and_then ( |t| {
1211
+ self . primitive_locations . get ( & t) . map ( |n| {
1212
+ let id = t. to_def_index ( ) ;
1213
+ DefId { krate : * n, index : id }
1214
+ } )
1207
1215
} )
1208
- } )
1216
+ }
1209
1217
}
1218
+ } else {
1219
+ unreachable ! ( )
1210
1220
} ;
1211
1221
if !self . seen_mod {
1212
1222
if let Some ( did) = did {
1213
1223
self . impls . entry ( did) . or_insert ( vec ! [ ] ) . push ( Impl {
1214
- impl_ : i,
1215
- dox : attrs. value ( "doc" ) . map ( |s|s. to_owned ( ) ) ,
1216
- stability : item. stability . clone ( ) ,
1224
+ impl_item : item,
1217
1225
} ) ;
1218
1226
}
1219
1227
}
@@ -1510,11 +1518,15 @@ impl<'a> Item<'a> {
1510
1518
// located, then we return `None`.
1511
1519
} else {
1512
1520
let cache = cache ( ) ;
1513
- let path = & cache. external_paths [ & self . item . def_id ] ;
1514
- let root = match cache. extern_locations [ & self . item . def_id . krate ] {
1515
- ( _, Remote ( ref s) ) => s. to_string ( ) ,
1516
- ( _, Local ) => self . cx . root_path . clone ( ) ,
1517
- ( _, Unknown ) => return None ,
1521
+ let path = match cache. external_paths . get ( & self . item . def_id ) {
1522
+ Some ( path) => path,
1523
+ None => return None ,
1524
+ } ;
1525
+ let root = match cache. extern_locations . get ( & self . item . def_id . krate ) {
1526
+ Some ( & ( _, Remote ( ref s) ) ) => s. to_string ( ) ,
1527
+ Some ( & ( _, Local ) ) => self . cx . root_path . clone ( ) ,
1528
+ Some ( & ( _, Unknown ) ) => return None ,
1529
+ None => return None ,
1518
1530
} ;
1519
1531
Some ( format ! ( "{root}{path}/{file}?gotosrc={goto}" ,
1520
1532
root = root,
@@ -2449,7 +2461,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
2449
2461
None => return Ok ( ( ) ) ,
2450
2462
} ;
2451
2463
let ( non_trait, traits) : ( Vec < _ > , _ ) = v. iter ( ) . partition ( |i| {
2452
- i. impl_ . trait_ . is_none ( )
2464
+ i. inner_impl ( ) . trait_ . is_none ( )
2453
2465
} ) ;
2454
2466
if !non_trait. is_empty ( ) {
2455
2467
let render_header = match what {
@@ -2473,19 +2485,19 @@ fn render_assoc_items(w: &mut fmt::Formatter,
2473
2485
}
2474
2486
if !traits. is_empty ( ) {
2475
2487
let deref_impl = traits. iter ( ) . find ( |t| {
2476
- t. impl_ . trait_ . def_id ( ) == c. deref_trait_did
2488
+ t. inner_impl ( ) . trait_ . def_id ( ) == c. deref_trait_did
2477
2489
} ) ;
2478
2490
if let Some ( impl_) = deref_impl {
2479
2491
render_deref_methods ( w, cx, impl_, containing_item) ?;
2480
2492
}
2481
2493
write ! ( w, "<h2 id='implementations'>Trait \
2482
2494
Implementations</h2>") ?;
2483
2495
let ( derived, manual) : ( Vec < _ > , Vec < & Impl > ) = traits. iter ( ) . partition ( |i| {
2484
- i. impl_ . derived
2496
+ i. inner_impl ( ) . derived
2485
2497
} ) ;
2486
2498
for i in & manual {
2487
2499
let did = i. trait_did ( ) . unwrap ( ) ;
2488
- let assoc_link = AssocItemLink :: GotoSource ( did, & i. impl_ . provided_trait_methods ) ;
2500
+ let assoc_link = AssocItemLink :: GotoSource ( did, & i. inner_impl ( ) . provided_trait_methods ) ;
2489
2501
render_impl ( w, cx, i, assoc_link, true , containing_item. stable_since ( ) ) ?;
2490
2502
}
2491
2503
if !derived. is_empty ( ) {
@@ -2494,7 +2506,8 @@ fn render_assoc_items(w: &mut fmt::Formatter,
2494
2506
</h3>") ?;
2495
2507
for i in & derived {
2496
2508
let did = i. trait_did ( ) . unwrap ( ) ;
2497
- let assoc_link = AssocItemLink :: GotoSource ( did, & i. impl_ . provided_trait_methods ) ;
2509
+ let assoc_link = AssocItemLink :: GotoSource ( did,
2510
+ & i. inner_impl ( ) . provided_trait_methods ) ;
2498
2511
render_impl ( w, cx, i, assoc_link, true , containing_item. stable_since ( ) ) ?;
2499
2512
}
2500
2513
}
@@ -2504,8 +2517,8 @@ fn render_assoc_items(w: &mut fmt::Formatter,
2504
2517
2505
2518
fn render_deref_methods ( w : & mut fmt:: Formatter , cx : & Context , impl_ : & Impl ,
2506
2519
container_item : & clean:: Item ) -> fmt:: Result {
2507
- let deref_type = impl_. impl_ . trait_ . as_ref ( ) . unwrap ( ) ;
2508
- let target = impl_. impl_ . items . iter ( ) . filter_map ( |item| {
2520
+ let deref_type = impl_. inner_impl ( ) . trait_ . as_ref ( ) . unwrap ( ) ;
2521
+ let target = impl_. inner_impl ( ) . items . iter ( ) . filter_map ( |item| {
2509
2522
match item. inner {
2510
2523
clean:: TypedefItem ( ref t, true ) => Some ( & t. type_ ) ,
2511
2524
_ => None ,
@@ -2531,11 +2544,18 @@ fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl,
2531
2544
fn render_impl ( w : & mut fmt:: Formatter , cx : & Context , i : & Impl , link : AssocItemLink ,
2532
2545
render_header : bool , outer_version : Option < & str > ) -> fmt:: Result {
2533
2546
if render_header {
2534
- write ! ( w, "<h3 class='impl'><code>{}</code>" , i. impl_ ) ?;
2535
- let since = i. stability . as_ref ( ) . map ( |s| & s. since [ ..] ) ;
2547
+ write ! ( w, "<h3 class='impl'><span class='in-band'>< code>{}</code>" , i. inner_impl ( ) ) ?;
2548
+ let since = i. impl_item . stability . as_ref ( ) . map ( |s| & s. since [ ..] ) ;
2536
2549
render_stability_since_raw ( w, since, outer_version) ?;
2537
- write ! ( w, "</h3>" ) ?;
2538
- if let Some ( ref dox) = i. dox {
2550
+ write ! ( w, "</span><span class='out-of-band'>" ) ?;
2551
+ if let Some ( l) = ( Item { item : & i. impl_item , cx : cx } ) . href ( ) {
2552
+ write ! ( w, "<a id='src-{}' class='srclink' \
2553
+ href='{}' title='{}'>[src]</a>",
2554
+ i. impl_item. def_id. index. as_usize( ) , l, "goto source code" ) ?;
2555
+ }
2556
+ write ! ( w, "</span>" ) ?;
2557
+ write ! ( w, "</h3>\n " ) ?;
2558
+ if let Some ( ref dox) = i. impl_item . attrs . value ( "doc" ) {
2539
2559
write ! ( w, "<div class='docblock'>{}</div>" , Markdown ( dox) ) ?;
2540
2560
}
2541
2561
}
@@ -2601,7 +2621,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2601
2621
}
2602
2622
2603
2623
write ! ( w, "<div class='impl-items'>" ) ?;
2604
- for trait_item in & i. impl_ . items {
2624
+ for trait_item in & i. inner_impl ( ) . items {
2605
2625
doctraititem ( w, cx, trait_item, link, render_header, false , outer_version) ?;
2606
2626
}
2607
2627
@@ -2629,7 +2649,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2629
2649
// default items which weren't overridden in the implementation block.
2630
2650
if let Some ( did) = i. trait_did ( ) {
2631
2651
if let Some ( t) = cache ( ) . traits . get ( & did) {
2632
- render_default_items ( w, cx, t, & i. impl_ , render_header, outer_version) ?;
2652
+ render_default_items ( w, cx, t, & i. inner_impl ( ) , render_header, outer_version) ?;
2633
2653
}
2634
2654
}
2635
2655
write ! ( w, "</div>" ) ?;
0 commit comments