13
13
//! --resource-suffix flag and are emitted when --emit-type is empty (default)
14
14
//! or contains "invocation-specific".
15
15
16
+ use std:: borrow:: Cow ;
16
17
use std:: cell:: RefCell ;
17
18
use std:: ffi:: OsString ;
18
19
use std:: fs:: File ;
@@ -284,7 +285,7 @@ enum CrateInfoVersion {
284
285
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
285
286
#[ serde( transparent) ]
286
287
struct PartsAndLocations < P > {
287
- parts : Vec < ( PathBuf , P ) > ,
288
+ parts : Vec < ( Cow < ' static , Path > , P ) > ,
288
289
}
289
290
290
291
impl < P > Default for PartsAndLocations < P > {
@@ -294,12 +295,12 @@ impl<P> Default for PartsAndLocations<P> {
294
295
}
295
296
296
297
impl < T , U > PartsAndLocations < Part < T , U > > {
297
- fn push ( & mut self , path : PathBuf , item : U ) {
298
- self . parts . push ( ( path, Part { _artifact : PhantomData , item } ) ) ;
298
+ fn push ( & mut self , path : impl Into < Cow < ' static , Path > > , item : U ) {
299
+ self . parts . push ( ( path. into ( ) , Part { _artifact : PhantomData , item } ) ) ;
299
300
}
300
301
301
302
/// Singleton part, one file
302
- fn with ( path : PathBuf , part : U ) -> Self {
303
+ fn with ( path : impl Into < Cow < ' static , Path > > , part : U ) -> Self {
303
304
let mut ret = Self :: default ( ) ;
304
305
ret. push ( path, part) ;
305
306
ret
@@ -439,24 +440,20 @@ impl CratesIndexPart {
439
440
let content =
440
441
format ! ( "<h1>List of all crates</h1><ul class=\" all-items\" >{DELIMITER}</ul>" ) ;
441
442
let template = layout:: render ( layout, & page, "" , content, style_files) ;
442
- match SortedTemplate :: from_template ( & template, DELIMITER ) {
443
- Ok ( template) => template,
444
- Err ( e) => panic ! (
445
- "Object Replacement Character (U+FFFC) should not appear in the --index-page: {e}"
446
- ) ,
447
- }
443
+ SortedTemplate :: from_template ( & template, DELIMITER )
444
+ . expect ( "Object Replacement Character (U+FFFC) should not appear in the --index-page" )
448
445
}
449
446
450
447
/// Might return parts that are duplicate with ones in prexisting index.html
451
448
fn get ( crate_name : & str , external_crates : & [ String ] ) -> Result < PartsAndLocations < Self > , Error > {
452
449
let mut ret = PartsAndLocations :: default ( ) ;
453
- let path = PathBuf :: from ( "index.html" ) ;
450
+ let path = Path :: new ( "index.html" ) ;
454
451
for crate_name in external_crates. iter ( ) . map ( |s| s. as_str ( ) ) . chain ( once ( crate_name) ) {
455
452
let part = format ! (
456
453
"<li><a href=\" {trailing_slash}index.html\" >{crate_name}</a></li>" ,
457
454
trailing_slash = ensure_trailing_slash( crate_name) ,
458
455
) ;
459
- ret. push ( path. clone ( ) , part) ;
456
+ ret. push ( path, part) ;
460
457
}
461
458
Ok ( ret)
462
459
}
@@ -600,7 +597,6 @@ impl TypeAliasPart {
600
597
cx,
601
598
} ;
602
599
DocVisitor :: visit_crate ( & mut type_impl_collector, krate) ;
603
- let cx = type_impl_collector. cx ;
604
600
let aliased_types = type_impl_collector. aliased_types ;
605
601
for aliased_type in aliased_types. values ( ) {
606
602
let impls = aliased_type. impl_ . values ( ) . filter_map (
@@ -612,7 +608,7 @@ impl TypeAliasPart {
612
608
for & ( type_alias_fqp, type_alias_item) in type_aliases {
613
609
cx. id_map . borrow_mut ( ) . clear ( ) ;
614
610
cx. deref_id_map . borrow_mut ( ) . clear ( ) ;
615
- let type_alias_fqp = ( * type_alias_fqp) . iter ( ) . join ( "::" ) ;
611
+ let type_alias_fqp = type_alias_fqp. iter ( ) . join ( "::" ) ;
616
612
if let Some ( ret) = & mut ret {
617
613
ret. aliases . push ( type_alias_fqp) ;
618
614
} else {
@@ -737,7 +733,7 @@ impl TraitAliasPart {
737
733
} ,
738
734
} ;
739
735
740
- let implementors = imps
736
+ let mut implementors = imps
741
737
. iter ( )
742
738
. filter_map ( |imp| {
743
739
// If the trait and implementation are in the same crate, then
@@ -759,12 +755,12 @@ impl TraitAliasPart {
759
755
} )
760
756
}
761
757
} )
762
- . collect :: < Vec < _ > > ( ) ;
758
+ . peekable ( ) ;
763
759
764
760
// Only create a js file if we have impls to add to it. If the trait is
765
761
// documented locally though we always create the file to avoid dead
766
762
// links.
767
- if implementors. is_empty ( ) && !cache. paths . contains_key ( & did) {
763
+ if implementors. peek ( ) . is_none ( ) && !cache. paths . contains_key ( & did) {
768
764
continue ;
769
765
}
770
766
@@ -775,11 +771,7 @@ impl TraitAliasPart {
775
771
path. push ( format ! ( "{remote_item_type}.{}.js" , remote_path[ remote_path. len( ) - 1 ] ) ) ;
776
772
777
773
let part = OrderedJson :: array_sorted (
778
- implementors
779
- . iter ( )
780
- . map ( OrderedJson :: serialize)
781
- . collect :: < Result < Vec < _ > , _ > > ( )
782
- . unwrap ( ) ,
774
+ implementors. map ( |implementor| OrderedJson :: serialize ( implementor) . unwrap ( ) ) ,
783
775
) ;
784
776
path_parts. push ( path, OrderedJson :: array_unsorted ( [ crate_name_json, & part] ) ) ;
785
777
}
@@ -874,9 +866,8 @@ impl<'item> DocVisitor<'item> for TypeImplCollector<'_, '_, 'item> {
874
866
let impl_ = cache
875
867
. impls
876
868
. get ( & target_did)
877
- . map ( |v| & v[ ..] )
878
- . unwrap_or_default ( )
879
- . iter ( )
869
+ . into_iter ( )
870
+ . flatten ( )
880
871
. map ( |impl_| {
881
872
( impl_. impl_item . item_id , AliasedTypeImpl { impl_, type_aliases : Vec :: new ( ) } )
882
873
} )
@@ -891,14 +882,8 @@ impl<'item> DocVisitor<'item> for TypeImplCollector<'_, '_, 'item> {
891
882
// Exclude impls that are directly on this type. They're already in the HTML.
892
883
// Some inlining scenarios can cause there to be two versions of the same
893
884
// impl: one on the type alias and one on the underlying target type.
894
- let mut seen_impls: FxHashSet < ItemId > = cache
895
- . impls
896
- . get ( & self_did)
897
- . map ( |s| & s[ ..] )
898
- . unwrap_or_default ( )
899
- . iter ( )
900
- . map ( |i| i. impl_item . item_id )
901
- . collect ( ) ;
885
+ let mut seen_impls: FxHashSet < ItemId > =
886
+ cache. impls . get ( & self_did) . into_iter ( ) . flatten ( ) . map ( |i| i. impl_item . item_id ) . collect ( ) ;
902
887
for ( impl_item_id, aliased_type_impl) in & mut aliased_type. impl_ {
903
888
// Only include this impl if it actually unifies with this alias.
904
889
// Synthetic impls are not included; those are also included in the HTML.
0 commit comments