@@ -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 ) > ,
@@ -971,12 +964,12 @@ fn write_shared(cx: &Context,
971
964
// there's no need to emit information about it (there's inlining
972
965
// going on). If they're in different crates then the crate defining
973
966
// the trait will be interested in our implementation.
974
- if imp. def_id . krate == did. krate { continue }
967
+ if imp. impl_item . def_id . krate == did. krate { continue }
975
968
// If the implementation is from another crate then that crate
976
969
// should add it.
977
- if !imp. def_id . is_local ( ) { continue }
970
+ if !imp. impl_item . def_id . is_local ( ) { continue }
978
971
have_impls = true ;
979
- write ! ( implementors, "{}," , as_json( & imp. impl_ . to_string( ) ) ) . unwrap ( ) ;
972
+ write ! ( implementors, "{}," , as_json( & imp. inner_impl ( ) . to_string( ) ) ) . unwrap ( ) ;
980
973
}
981
974
implementors. push_str ( "];" ) ;
982
975
@@ -1208,10 +1201,8 @@ impl DocFolder for Cache {
1208
1201
if !self . masked_crates . contains ( & item. def_id . krate ) {
1209
1202
if let Some ( did) = i. trait_ . def_id ( ) {
1210
1203
if i. for_ . def_id ( ) . map_or ( true , |d| !self . masked_crates . contains ( & d. krate ) ) {
1211
- self . implementors . entry ( did) . or_insert ( vec ! [ ] ) . push ( Implementor {
1212
- def_id : item. def_id ,
1213
- stability : item. stability . clone ( ) ,
1214
- impl_ : i. clone ( ) ,
1204
+ self . implementors . entry ( did) . or_insert ( vec ! [ ] ) . push ( Impl {
1205
+ impl_item : item. clone ( ) ,
1215
1206
} ) ;
1216
1207
}
1217
1208
}
@@ -2338,18 +2329,6 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2338
2329
document ( w, cx, it)
2339
2330
}
2340
2331
2341
- fn implementor2item < ' a > ( cache : & ' a Cache , imp : & Implementor ) -> Option < & ' a clean:: Item > {
2342
- if let Some ( t_did) = imp. impl_ . for_ . def_id ( ) {
2343
- if let Some ( impl_item) = cache. impls . get ( & t_did) . and_then ( |i| i. iter ( )
2344
- . find ( |i| i. impl_item . def_id == imp. def_id ) )
2345
- {
2346
- let i = & impl_item. impl_item ;
2347
- return Some ( i) ;
2348
- }
2349
- }
2350
- None
2351
- }
2352
-
2353
2332
fn item_trait ( w : & mut fmt:: Formatter , cx : & Context , it : & clean:: Item ,
2354
2333
t : & clean:: Trait ) -> fmt:: Result {
2355
2334
let mut bounds = String :: new ( ) ;
@@ -2533,7 +2512,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2533
2512
// if any Types with the same name but different DefId have been found.
2534
2513
let mut implementor_dups: FxHashMap < & str , ( DefId , bool ) > = FxHashMap ( ) ;
2535
2514
for implementor in implementors {
2536
- match implementor. impl_ . for_ {
2515
+ match implementor. inner_impl ( ) . for_ {
2537
2516
clean:: ResolvedPath { ref path, did, is_generic : false , .. } |
2538
2517
clean:: BorrowedRef {
2539
2518
type_ : box clean:: ResolvedPath { ref path, did, is_generic : false , .. } ,
@@ -2550,7 +2529,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2550
2529
}
2551
2530
2552
2531
let ( local, foreign) = implementors. iter ( )
2553
- . partition :: < Vec < _ > , _ > ( |i| i. impl_ . for_ . def_id ( )
2532
+ . partition :: < Vec < _ > , _ > ( |i| i. inner_impl ( ) . for_ . def_id ( )
2554
2533
. map_or ( true , |d| cache. paths . contains_key ( & d) ) ) ;
2555
2534
2556
2535
if !foreign. is_empty ( ) {
@@ -2561,42 +2540,37 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2561
2540
" ) ?;
2562
2541
2563
2542
for implementor in foreign {
2564
- if let Some ( i) = implementor2item ( & cache, implementor) {
2565
- let impl_ = Impl { impl_item : i. clone ( ) } ;
2566
- let assoc_link = AssocItemLink :: GotoSource (
2567
- i. def_id , & implementor. impl_ . provided_trait_methods
2568
- ) ;
2569
- render_impl ( w, cx, & impl_, assoc_link,
2570
- RenderMode :: Normal , i. stable_since ( ) , false ) ?;
2571
- }
2543
+ let assoc_link = AssocItemLink :: GotoSource (
2544
+ implementor. impl_item . def_id , & implementor. inner_impl ( ) . provided_trait_methods
2545
+ ) ;
2546
+ render_impl ( w, cx, & implementor, assoc_link,
2547
+ RenderMode :: Normal , implementor. impl_item . stable_since ( ) , false ) ?;
2572
2548
}
2573
2549
}
2574
2550
2575
2551
write ! ( w, "{}" , impl_header) ?;
2576
2552
2577
2553
for implementor in local {
2578
2554
write ! ( w, "<li>" ) ?;
2579
- if let Some ( item) = implementor2item ( & cache, implementor) {
2580
- if let Some ( l) = ( Item { cx, item } ) . src_href ( ) {
2581
- write ! ( w, "<div class='out-of-band'>" ) ?;
2582
- write ! ( w, "<a class='srclink' href='{}' title='{}'>[src]</a>" ,
2583
- l, "goto source code" ) ?;
2584
- write ! ( w, "</div>" ) ?;
2585
- }
2555
+ if let Some ( l) = ( Item { cx, item : & implementor. impl_item } ) . src_href ( ) {
2556
+ write ! ( w, "<div class='out-of-band'>" ) ?;
2557
+ write ! ( w, "<a class='srclink' href='{}' title='{}'>[src]</a>" ,
2558
+ l, "goto source code" ) ?;
2559
+ write ! ( w, "</div>" ) ?;
2586
2560
}
2587
2561
write ! ( w, "<code>" ) ?;
2588
2562
// If there's already another implementor that has the same abbridged name, use the
2589
2563
// full path, for example in `std::iter::ExactSizeIterator`
2590
- let use_absolute = match implementor. impl_ . for_ {
2564
+ let use_absolute = match implementor. inner_impl ( ) . for_ {
2591
2565
clean:: ResolvedPath { ref path, is_generic : false , .. } |
2592
2566
clean:: BorrowedRef {
2593
2567
type_ : box clean:: ResolvedPath { ref path, is_generic : false , .. } ,
2594
2568
..
2595
2569
} => implementor_dups[ path. last_name ( ) ] . 1 ,
2596
2570
_ => false ,
2597
2571
} ;
2598
- fmt_impl_for_trait_page ( & implementor. impl_ , w, use_absolute) ?;
2599
- for it in & implementor. impl_ . items {
2572
+ fmt_impl_for_trait_page ( & implementor. inner_impl ( ) , w, use_absolute) ?;
2573
+ for it in & implementor. inner_impl ( ) . items {
2600
2574
if let clean:: TypedefItem ( ref tydef, _) = it. inner {
2601
2575
write ! ( w, "<span class=\" where fmt-newline\" > " ) ?;
2602
2576
assoc_type ( w, it, & vec ! [ ] , Some ( & tydef. type_ ) , AssocItemLink :: Anchor ( None ) ) ?;
@@ -3886,20 +3860,16 @@ fn sidebar_trait(fmt: &mut fmt::Formatter, it: &clean::Item,
3886
3860
3887
3861
if let Some ( implementors) = c. implementors . get ( & it. def_id ) {
3888
3862
let res = implementors. iter ( )
3889
- . filter ( |i| i. impl_ . for_ . def_id ( )
3890
- . map_or ( false , |d| !c. paths . contains_key ( & d) ) )
3863
+ . filter ( |i| i. inner_impl ( ) . for_ . def_id ( )
3864
+ . map_or ( false , |d| !c. paths . contains_key ( & d) ) )
3891
3865
. filter_map ( |i| {
3892
- if let Some ( item) = implementor2item ( & c, i) {
3893
- match extract_for_impl_name ( & item) {
3894
- Some ( ( ref name, ref url) ) => {
3895
- Some ( format ! ( "<a href=\" #impl-{}\" >{}</a>" ,
3896
- small_url_encode( url) ,
3897
- Escape ( name) ) )
3898
- }
3899
- _ => None ,
3866
+ match extract_for_impl_name ( & i. impl_item ) {
3867
+ Some ( ( ref name, ref url) ) => {
3868
+ Some ( format ! ( "<a href=\" #impl-{}\" >{}</a>" ,
3869
+ small_url_encode( url) ,
3870
+ Escape ( name) ) )
3900
3871
}
3901
- } else {
3902
- None
3872
+ _ => None ,
3903
3873
}
3904
3874
} )
3905
3875
. collect :: < String > ( ) ;
0 commit comments