@@ -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 } ;
@@ -718,18 +718,20 @@ fn write_shared(cx: &Context,
718
718
719
719
// Update the search index
720
720
let dst = cx. dst . join ( "search-index.js" ) ;
721
- let all_indexes = try_err ! ( collect( & dst, & krate. name, "searchIndex" ) , & dst) ;
721
+ let mut all_indexes = try_err ! ( collect( & dst, & krate. name, "searchIndex" ) , & dst) ;
722
+ all_indexes. push ( search_index) ;
723
+ // Sort the indexes by crate so the file will be generated identically even
724
+ // with rustdoc running in parallel.
725
+ all_indexes. sort ( ) ;
722
726
let mut w = try_err ! ( File :: create( & dst) , & dst) ;
723
727
try_err ! ( writeln!( & mut w, "var searchIndex = {{}};" ) , & dst) ;
724
- try_err ! ( writeln!( & mut w, "{}" , search_index) , & dst) ;
725
728
for index in & all_indexes {
726
729
try_err ! ( writeln!( & mut w, "{}" , * index) , & dst) ;
727
730
}
728
731
try_err ! ( writeln!( & mut w, "initSearch(searchIndex);" ) , & dst) ;
729
732
730
733
// Update the list of all implementors for traits
731
734
let dst = cx. dst . join ( "implementors" ) ;
732
- try_err ! ( mkdir( & dst) , & dst) ;
733
735
for ( & did, imps) in & cache. implementors {
734
736
// Private modules can leak through to this phase of rustdoc, which
735
737
// could contain implementations for otherwise private types. In some
@@ -746,37 +748,37 @@ fn write_shared(cx: &Context,
746
748
}
747
749
} ;
748
750
751
+ let mut implementors = format ! ( r#"implementors["{}"] = ["# , krate. name) ;
752
+ for imp in imps {
753
+ // If the trait and implementation are in the same crate, then
754
+ // there's no need to emit information about it (there's inlining
755
+ // going on). If they're in different crates then the crate defining
756
+ // the trait will be interested in our implementation.
757
+ if imp. def_id . krate == did. krate { continue }
758
+ write ! ( implementors, r#""{}","# , imp. impl_) . unwrap ( ) ;
759
+ }
760
+ implementors. push_str ( "];" ) ;
761
+
749
762
let mut mydst = dst. clone ( ) ;
750
763
for part in & remote_path[ ..remote_path. len ( ) - 1 ] {
751
764
mydst. push ( part) ;
752
- try_err ! ( mkdir( & mydst) , & mydst) ;
753
765
}
766
+ try_err ! ( fs:: create_dir_all( & mydst) , & mydst) ;
754
767
mydst. push ( & format ! ( "{}.{}.js" ,
755
768
remote_item_type. css_class( ) ,
756
769
remote_path[ remote_path. len( ) - 1 ] ) ) ;
757
- let all_implementors = try_err ! ( collect( & mydst, & krate. name,
758
- "implementors" ) ,
759
- & mydst) ;
760
770
761
- try_err ! ( mkdir( mydst. parent( ) . unwrap( ) ) ,
762
- & mydst. parent( ) . unwrap( ) . to_path_buf( ) ) ;
763
- let mut f = BufWriter :: new ( try_err ! ( File :: create( & mydst) , & mydst) ) ;
764
- try_err ! ( writeln!( & mut f, "(function() {{var implementors = {{}};" ) , & mydst) ;
771
+ let mut all_implementors = try_err ! ( collect( & mydst, & krate. name, "implementors" ) , & mydst) ;
772
+ all_implementors. push ( implementors) ;
773
+ // Sort the implementors by crate so the file will be generated
774
+ // identically even with rustdoc running in parallel.
775
+ all_implementors. sort ( ) ;
765
776
777
+ let mut f = try_err ! ( File :: create( & mydst) , & mydst) ;
778
+ try_err ! ( writeln!( & mut f, "(function() {{var implementors = {{}};" ) , & mydst) ;
766
779
for implementor in & all_implementors {
767
- try_err ! ( write!( & mut f, "{}" , * implementor) , & mydst) ;
768
- }
769
-
770
- try_err ! ( write!( & mut f, r#"implementors["{}"] = ["# , krate. name) , & mydst) ;
771
- for imp in imps {
772
- // If the trait and implementation are in the same crate, then
773
- // there's no need to emit information about it (there's inlining
774
- // going on). If they're in different crates then the crate defining
775
- // the trait will be interested in our implementation.
776
- if imp. def_id . krate == did. krate { continue }
777
- try_err ! ( write!( & mut f, r#""{}","# , imp. impl_) , & mydst) ;
780
+ try_err ! ( writeln!( & mut f, "{}" , * implementor) , & mydst) ;
778
781
}
779
- try_err ! ( writeln!( & mut f, r"];" ) , & mydst) ;
780
782
try_err ! ( writeln!( & mut f, "{}" , r"
781
783
if (window.register_implementors) {
782
784
window.register_implementors(implementors);
0 commit comments