@@ -40,7 +40,7 @@ use std::cmp::Ordering;
4040use std:: collections:: BTreeMap ;
4141use std:: default:: Default ;
4242use std:: error;
43- use std:: fmt:: { self , Display , Formatter } ;
43+ use std:: fmt:: { self , Display , Formatter , Write as FmtWrite } ;
4444use std:: fs:: { self , File , OpenOptions } ;
4545use std:: io:: prelude:: * ;
4646use std:: io:: { self , BufWriter , BufReader } ;
@@ -718,18 +718,20 @@ fn write_shared(cx: &Context,
718718
719719 // Update the search index
720720 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 ( ) ;
722726 let mut w = try_err ! ( File :: create( & dst) , & dst) ;
723727 try_err ! ( writeln!( & mut w, "var searchIndex = {{}};" ) , & dst) ;
724- try_err ! ( writeln!( & mut w, "{}" , search_index) , & dst) ;
725728 for index in & all_indexes {
726729 try_err ! ( writeln!( & mut w, "{}" , * index) , & dst) ;
727730 }
728731 try_err ! ( writeln!( & mut w, "initSearch(searchIndex);" ) , & dst) ;
729732
730733 // Update the list of all implementors for traits
731734 let dst = cx. dst . join ( "implementors" ) ;
732- try_err ! ( mkdir( & dst) , & dst) ;
733735 for ( & did, imps) in & cache. implementors {
734736 // Private modules can leak through to this phase of rustdoc, which
735737 // could contain implementations for otherwise private types. In some
@@ -746,37 +748,37 @@ fn write_shared(cx: &Context,
746748 }
747749 } ;
748750
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+
749762 let mut mydst = dst. clone ( ) ;
750763 for part in & remote_path[ ..remote_path. len ( ) - 1 ] {
751764 mydst. push ( part) ;
752- try_err ! ( mkdir( & mydst) , & mydst) ;
753765 }
766+ try_err ! ( fs:: create_dir_all( & mydst) , & mydst) ;
754767 mydst. push ( & format ! ( "{}.{}.js" ,
755768 remote_item_type. css_class( ) ,
756769 remote_path[ remote_path. len( ) - 1 ] ) ) ;
757- let all_implementors = try_err ! ( collect( & mydst, & krate. name,
758- "implementors" ) ,
759- & mydst) ;
760770
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 ( ) ;
765776
777+ let mut f = try_err ! ( File :: create( & mydst) , & mydst) ;
778+ try_err ! ( writeln!( & mut f, "(function() {{var implementors = {{}};" ) , & mydst) ;
766779 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) ;
778781 }
779- try_err ! ( writeln!( & mut f, r"];" ) , & mydst) ;
780782 try_err ! ( writeln!( & mut f, "{}" , r"
781783 if (window.register_implementors) {
782784 window.register_implementors(implementors);
0 commit comments