@@ -173,14 +173,7 @@ pub enum ExternalLocation {
173
173
Unknown ,
174
174
}
175
175
176
- /// Metadata about an implementor of a trait.
177
- pub struct Implementor {
178
- pub def_id : DefId ,
179
- pub stability : Option < clean:: Stability > ,
180
- pub impl_ : clean:: Impl ,
181
- }
182
-
183
- /// Metadata about implementations for a type.
176
+ /// Metadata about implementations for a type or trait.
184
177
#[ derive( Clone ) ]
185
178
pub struct Impl {
186
179
pub impl_item : clean:: Item ,
@@ -279,7 +272,7 @@ pub struct Cache {
279
272
/// When rendering traits, it's often useful to be able to list all
280
273
/// implementors of the trait, and this mapping is exactly, that: a mapping
281
274
/// of trait ids to the list of known implementors of the trait
282
- pub implementors : FxHashMap < DefId , Vec < Implementor > > ,
275
+ pub implementors : FxHashMap < DefId , Vec < Impl > > ,
283
276
284
277
/// Cache of where external crate documentation can be found.
285
278
pub extern_locations : FxHashMap < CrateNum , ( String , PathBuf , ExternalLocation ) > ,
@@ -965,12 +958,12 @@ fn write_shared(cx: &Context,
965
958
// there's no need to emit information about it (there's inlining
966
959
// going on). If they're in different crates then the crate defining
967
960
// the trait will be interested in our implementation.
968
- if imp. def_id . krate == did. krate { continue }
961
+ if imp. impl_item . def_id . krate == did. krate { continue }
969
962
// If the implementation is from another crate then that crate
970
963
// should add it.
971
- if !imp. def_id . is_local ( ) { continue }
964
+ if !imp. impl_item . def_id . is_local ( ) { continue }
972
965
have_impls = true ;
973
- write ! ( implementors, "{}," , as_json( & imp. impl_ . to_string( ) ) ) . unwrap ( ) ;
966
+ write ! ( implementors, "{}," , as_json( & imp. inner_impl ( ) . to_string( ) ) ) . unwrap ( ) ;
974
967
}
975
968
implementors. push_str ( "];" ) ;
976
969
@@ -1202,10 +1195,8 @@ impl DocFolder for Cache {
1202
1195
if !self . masked_crates . contains ( & item. def_id . krate ) {
1203
1196
if let Some ( did) = i. trait_ . def_id ( ) {
1204
1197
if i. for_ . def_id ( ) . map_or ( true , |d| !self . masked_crates . contains ( & d. krate ) ) {
1205
- self . implementors . entry ( did) . or_insert ( vec ! [ ] ) . push ( Implementor {
1206
- def_id : item. def_id ,
1207
- stability : item. stability . clone ( ) ,
1208
- impl_ : i. clone ( ) ,
1198
+ self . implementors . entry ( did) . or_insert ( vec ! [ ] ) . push ( Impl {
1199
+ impl_item : item. clone ( ) ,
1209
1200
} ) ;
1210
1201
}
1211
1202
}
@@ -2332,18 +2323,6 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2332
2323
document ( w, cx, it)
2333
2324
}
2334
2325
2335
- fn implementor2item < ' a > ( cache : & ' a Cache , imp : & Implementor ) -> Option < & ' a clean:: Item > {
2336
- if let Some ( t_did) = imp. impl_ . for_ . def_id ( ) {
2337
- if let Some ( impl_item) = cache. impls . get ( & t_did) . and_then ( |i| i. iter ( )
2338
- . find ( |i| i. impl_item . def_id == imp. def_id ) )
2339
- {
2340
- let i = & impl_item. impl_item ;
2341
- return Some ( i) ;
2342
- }
2343
- }
2344
- None
2345
- }
2346
-
2347
2326
fn item_trait ( w : & mut fmt:: Formatter , cx : & Context , it : & clean:: Item ,
2348
2327
t : & clean:: Trait ) -> fmt:: Result {
2349
2328
let mut bounds = String :: new ( ) ;
@@ -2527,7 +2506,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2527
2506
// if any Types with the same name but different DefId have been found.
2528
2507
let mut implementor_dups: FxHashMap < & str , ( DefId , bool ) > = FxHashMap ( ) ;
2529
2508
for implementor in implementors {
2530
- match implementor. impl_ . for_ {
2509
+ match implementor. inner_impl ( ) . for_ {
2531
2510
clean:: ResolvedPath { ref path, did, is_generic : false , .. } |
2532
2511
clean:: BorrowedRef {
2533
2512
type_ : box clean:: ResolvedPath { ref path, did, is_generic : false , .. } ,
@@ -2544,7 +2523,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2544
2523
}
2545
2524
2546
2525
let ( local, foreign) = implementors. iter ( )
2547
- . partition :: < Vec < _ > , _ > ( |i| i. impl_ . for_ . def_id ( )
2526
+ . partition :: < Vec < _ > , _ > ( |i| i. inner_impl ( ) . for_ . def_id ( )
2548
2527
. map_or ( true , |d| cache. paths . contains_key ( & d) ) ) ;
2549
2528
2550
2529
if !foreign. is_empty ( ) {
@@ -2555,42 +2534,37 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2555
2534
" ) ?;
2556
2535
2557
2536
for implementor in foreign {
2558
- if let Some ( i) = implementor2item ( & cache, implementor) {
2559
- let impl_ = Impl { impl_item : i. clone ( ) } ;
2560
- let assoc_link = AssocItemLink :: GotoSource (
2561
- i. def_id , & implementor. impl_ . provided_trait_methods
2562
- ) ;
2563
- render_impl ( w, cx, & impl_, assoc_link,
2564
- RenderMode :: Normal , i. stable_since ( ) , false ) ?;
2565
- }
2537
+ let assoc_link = AssocItemLink :: GotoSource (
2538
+ implementor. impl_item . def_id , & implementor. inner_impl ( ) . provided_trait_methods
2539
+ ) ;
2540
+ render_impl ( w, cx, & implementor, assoc_link,
2541
+ RenderMode :: Normal , implementor. impl_item . stable_since ( ) , false ) ?;
2566
2542
}
2567
2543
}
2568
2544
2569
2545
write ! ( w, "{}" , impl_header) ?;
2570
2546
2571
2547
for implementor in local {
2572
2548
write ! ( w, "<li>" ) ?;
2573
- if let Some ( item) = implementor2item ( & cache, implementor) {
2574
- if let Some ( l) = ( Item { cx, item } ) . src_href ( ) {
2575
- write ! ( w, "<div class='out-of-band'>" ) ?;
2576
- write ! ( w, "<a class='srclink' href='{}' title='{}'>[src]</a>" ,
2577
- l, "goto source code" ) ?;
2578
- write ! ( w, "</div>" ) ?;
2579
- }
2549
+ if let Some ( l) = ( Item { cx, item : & implementor. impl_item } ) . src_href ( ) {
2550
+ write ! ( w, "<div class='out-of-band'>" ) ?;
2551
+ write ! ( w, "<a class='srclink' href='{}' title='{}'>[src]</a>" ,
2552
+ l, "goto source code" ) ?;
2553
+ write ! ( w, "</div>" ) ?;
2580
2554
}
2581
2555
write ! ( w, "<code>" ) ?;
2582
2556
// If there's already another implementor that has the same abbridged name, use the
2583
2557
// full path, for example in `std::iter::ExactSizeIterator`
2584
- let use_absolute = match implementor. impl_ . for_ {
2558
+ let use_absolute = match implementor. inner_impl ( ) . for_ {
2585
2559
clean:: ResolvedPath { ref path, is_generic : false , .. } |
2586
2560
clean:: BorrowedRef {
2587
2561
type_ : box clean:: ResolvedPath { ref path, is_generic : false , .. } ,
2588
2562
..
2589
2563
} => implementor_dups[ path. last_name ( ) ] . 1 ,
2590
2564
_ => false ,
2591
2565
} ;
2592
- fmt_impl_for_trait_page ( & implementor. impl_ , w, use_absolute) ?;
2593
- for it in & implementor. impl_ . items {
2566
+ fmt_impl_for_trait_page ( & implementor. inner_impl ( ) , w, use_absolute) ?;
2567
+ for it in & implementor. inner_impl ( ) . items {
2594
2568
if let clean:: TypedefItem ( ref tydef, _) = it. inner {
2595
2569
write ! ( w, "<span class=\" where fmt-newline\" > " ) ?;
2596
2570
assoc_type ( w, it, & vec ! [ ] , Some ( & tydef. type_ ) , AssocItemLink :: Anchor ( None ) ) ?;
@@ -3880,20 +3854,16 @@ fn sidebar_trait(fmt: &mut fmt::Formatter, it: &clean::Item,
3880
3854
3881
3855
if let Some ( implementors) = c. implementors . get ( & it. def_id ) {
3882
3856
let res = implementors. iter ( )
3883
- . filter ( |i| i. impl_ . for_ . def_id ( )
3884
- . map_or ( false , |d| !c. paths . contains_key ( & d) ) )
3857
+ . filter ( |i| i. inner_impl ( ) . for_ . def_id ( )
3858
+ . map_or ( false , |d| !c. paths . contains_key ( & d) ) )
3885
3859
. filter_map ( |i| {
3886
- if let Some ( item) = implementor2item ( & c, i) {
3887
- match extract_for_impl_name ( & item) {
3888
- Some ( ( ref name, ref url) ) => {
3889
- Some ( format ! ( "<a href=\" #impl-{}\" >{}</a>" ,
3890
- small_url_encode( url) ,
3891
- Escape ( name) ) )
3892
- }
3893
- _ => None ,
3860
+ match extract_for_impl_name ( & i. impl_item ) {
3861
+ Some ( ( ref name, ref url) ) => {
3862
+ Some ( format ! ( "<a href=\" #impl-{}\" >{}</a>" ,
3863
+ small_url_encode( url) ,
3864
+ Escape ( name) ) )
3894
3865
}
3895
- } else {
3896
- None
3866
+ _ => None ,
3897
3867
}
3898
3868
} )
3899
3869
. collect :: < String > ( ) ;
0 commit comments