@@ -40,7 +40,7 @@ use std::cmp::Ordering;
40
40
use std:: collections:: BTreeMap ;
41
41
use std:: default:: Default ;
42
42
use std:: error;
43
- use std:: fmt:: { self , Display , Formatter } ;
43
+ use std:: fmt:: { self , Display , Formatter , Write as FmtWrite } ;
44
44
use std:: fs:: { self , File , OpenOptions } ;
45
45
use std:: io:: prelude:: * ;
46
46
use std:: io:: { self , BufWriter , BufReader } ;
@@ -726,18 +726,20 @@ fn write_shared(cx: &Context,
726
726
727
727
// Update the search index
728
728
let dst = cx. dst . join ( "search-index.js" ) ;
729
- let all_indexes = try_err ! ( collect( & dst, & krate. name, "searchIndex" ) , & dst) ;
729
+ let mut all_indexes = try_err ! ( collect( & dst, & krate. name, "searchIndex" ) , & dst) ;
730
+ all_indexes. push ( search_index) ;
731
+ // Sort the indexes by crate so the file will be generated identically even
732
+ // with rustdoc running in parallel.
733
+ all_indexes. sort ( ) ;
730
734
let mut w = try_err ! ( File :: create( & dst) , & dst) ;
731
735
try_err ! ( writeln!( & mut w, "var searchIndex = {{}};" ) , & dst) ;
732
- try_err ! ( writeln!( & mut w, "{}" , search_index) , & dst) ;
733
736
for index in & all_indexes {
734
737
try_err ! ( writeln!( & mut w, "{}" , * index) , & dst) ;
735
738
}
736
739
try_err ! ( writeln!( & mut w, "initSearch(searchIndex);" ) , & dst) ;
737
740
738
741
// Update the list of all implementors for traits
739
742
let dst = cx. dst . join ( "implementors" ) ;
740
- try_err ! ( mkdir( & dst) , & dst) ;
741
743
for ( & did, imps) in & cache. implementors {
742
744
// Private modules can leak through to this phase of rustdoc, which
743
745
// could contain implementations for otherwise private types. In some
@@ -754,37 +756,37 @@ fn write_shared(cx: &Context,
754
756
}
755
757
} ;
756
758
759
+ let mut implementors = format ! ( r#"implementors["{}"] = ["# , krate. name) ;
760
+ for imp in imps {
761
+ // If the trait and implementation are in the same crate, then
762
+ // there's no need to emit information about it (there's inlining
763
+ // going on). If they're in different crates then the crate defining
764
+ // the trait will be interested in our implementation.
765
+ if imp. def_id . krate == did. krate { continue }
766
+ write ! ( implementors, r#""{}","# , imp. impl_) . unwrap ( ) ;
767
+ }
768
+ implementors. push_str ( "];" ) ;
769
+
757
770
let mut mydst = dst. clone ( ) ;
758
771
for part in & remote_path[ ..remote_path. len ( ) - 1 ] {
759
772
mydst. push ( part) ;
760
- try_err ! ( mkdir( & mydst) , & mydst) ;
761
773
}
774
+ try_err ! ( fs:: create_dir_all( & mydst) , & mydst) ;
762
775
mydst. push ( & format ! ( "{}.{}.js" ,
763
776
remote_item_type. css_class( ) ,
764
777
remote_path[ remote_path. len( ) - 1 ] ) ) ;
765
- let all_implementors = try_err ! ( collect( & mydst, & krate. name,
766
- "implementors" ) ,
767
- & mydst) ;
768
778
769
- try_err ! ( mkdir( mydst. parent( ) . unwrap( ) ) ,
770
- & mydst. parent( ) . unwrap( ) . to_path_buf( ) ) ;
771
- let mut f = BufWriter :: new ( try_err ! ( File :: create( & mydst) , & mydst) ) ;
772
- try_err ! ( writeln!( & mut f, "(function() {{var implementors = {{}};" ) , & mydst) ;
779
+ let mut all_implementors = try_err ! ( collect( & mydst, & krate. name, "implementors" ) , & mydst) ;
780
+ all_implementors. push ( implementors) ;
781
+ // Sort the implementors by crate so the file will be generated
782
+ // identically even with rustdoc running in parallel.
783
+ all_implementors. sort ( ) ;
773
784
785
+ let mut f = try_err ! ( File :: create( & mydst) , & mydst) ;
786
+ try_err ! ( writeln!( & mut f, "(function() {{var implementors = {{}};" ) , & mydst) ;
774
787
for implementor in & all_implementors {
775
- try_err ! ( write!( & mut f, "{}" , * implementor) , & mydst) ;
776
- }
777
-
778
- try_err ! ( write!( & mut f, r#"implementors["{}"] = ["# , krate. name) , & mydst) ;
779
- for imp in imps {
780
- // If the trait and implementation are in the same crate, then
781
- // there's no need to emit information about it (there's inlining
782
- // going on). If they're in different crates then the crate defining
783
- // the trait will be interested in our implementation.
784
- if imp. def_id . krate == did. krate { continue }
785
- try_err ! ( write!( & mut f, r#""{}","# , imp. impl_) , & mydst) ;
788
+ try_err ! ( writeln!( & mut f, "{}" , * implementor) , & mydst) ;
786
789
}
787
- try_err ! ( writeln!( & mut f, r"];" ) , & mydst) ;
788
790
try_err ! ( writeln!( & mut f, "{}" , r"
789
791
if (window.register_implementors) {
790
792
window.register_implementors(implementors);
0 commit comments