@@ -44,11 +44,11 @@ enum SharedResource<'a> {
4444 /// This file will never change, no matter what toolchain is used to build it.
4545 ///
4646 /// It does not have a resource suffix.
47- Unversioned { name : & ' a str } ,
47+ Unversioned { name : & ' static str } ,
4848 /// This file may change depending on the toolchain.
4949 ///
5050 /// It has a resource suffix.
51- ToolchainSpecific { basename : & ' a str } ,
51+ ToolchainSpecific { basename : & ' static str } ,
5252 /// This file may change for any crate within a build.
5353 ///
5454 /// This differs from normal crate-specific files because it has a resource suffix.
@@ -157,11 +157,16 @@ pub(super) fn write_shared(
157157 & options. emit ,
158158 )
159159 } ;
160- let write_toolchain = |p : & _ , c : & _ | {
160+ // Toolchain resources should never be dynamic.
161+ let write_toolchain = |p : & ' static _ , c : & ' static _ | {
161162 cx. write_shared ( SharedResource :: ToolchainSpecific { basename : p } , c, & options. emit )
162163 } ;
163- let write_crate =
164- |p, c : & _ | cx. write_shared ( SharedResource :: CrateSpecific { basename : p } , c, & options. emit ) ;
164+
165+ // Crate resources should always be dynamic.
166+ let write_crate = |p : & _ , make_content : & dyn Fn ( ) -> Result < Vec < u8 > , Error > | {
167+ let content = make_content ( ) ?;
168+ cx. write_shared ( SharedResource :: CrateSpecific { basename : p } , content, & options. emit )
169+ } ;
165170
166171 // Add all the static files. These may already exist, but we just
167172 // overwrite them anyway to make sure that they're fresh and up-to-date.
@@ -185,10 +190,8 @@ pub(super) fn write_shared(
185190 "ayu" => write_minify ( "ayu.css" , static_files:: themes:: AYU ) ?,
186191 _ => {
187192 // Handle added third-party themes
188- let content = try_err ! ( fs:: read( & entry. path) , & entry. path) ;
189- // This is not exactly right: if compiled a second time with the same toolchain but different CLI args, the file could be different.
190- // But docs.rs doesn't use this, so hopefully the issue doesn't come up.
191- write_toolchain ( & format ! ( "{}.{}" , theme, extension) , content. as_slice ( ) ) ?;
193+ let filename = format ! ( "{}.{}" , theme, extension) ;
194+ write_crate ( & filename, & || Ok ( try_err ! ( fs:: read( & entry. path) , & entry. path) ) ) ?;
192195 }
193196 } ;
194197
@@ -367,19 +370,22 @@ pub(super) fn write_shared(
367370 }
368371
369372 let dst = cx. dst . join ( & format ! ( "source-files{}.js" , cx. shared. resource_suffix) ) ;
370- let ( mut all_sources, _krates) =
371- try_err ! ( collect( & dst, & krate. name. as_str( ) , "sourcesIndex" ) , & dst) ;
372- all_sources. push ( format ! (
373- "sourcesIndex[\" {}\" ] = {};" ,
374- & krate. name,
375- hierarchy. to_json_string( )
376- ) ) ;
377- all_sources. sort ( ) ;
378- let v = format ! (
379- "var N = null;var sourcesIndex = {{}};\n {}\n createSourceSidebar();\n " ,
380- all_sources. join( "\n " )
381- ) ;
382- write_crate ( "source-files.js" , & v) ?;
373+ let make_sources = || {
374+ let ( mut all_sources, _krates) =
375+ try_err ! ( collect( & dst, & krate. name. as_str( ) , "sourcesIndex" ) , & dst) ;
376+ all_sources. push ( format ! (
377+ "sourcesIndex[\" {}\" ] = {};" ,
378+ & krate. name,
379+ hierarchy. to_json_string( )
380+ ) ) ;
381+ all_sources. sort ( ) ;
382+ Ok ( format ! (
383+ "var N = null;var sourcesIndex = {{}};\n {}\n createSourceSidebar();\n " ,
384+ all_sources. join( "\n " )
385+ )
386+ . into_bytes ( ) )
387+ } ;
388+ write_crate ( "source-files.js" , & make_sources) ?;
383389 }
384390
385391 // Update the search index and crate list.
@@ -392,16 +398,17 @@ pub(super) fn write_shared(
392398 // Sort the indexes by crate so the file will be generated identically even
393399 // with rustdoc running in parallel.
394400 all_indexes. sort ( ) ;
395- {
401+ write_crate ( "search-index.js" , & || {
396402 let mut v = String :: from ( "var searchIndex = JSON.parse('{\\ \n " ) ;
397403 v. push_str ( & all_indexes. join ( ",\\ \n " ) ) ;
398404 v. push_str ( "\\ \n }');\n initSearch(searchIndex);" ) ;
399- write_crate ( "search-index.js" , & v ) ? ;
400- }
405+ Ok ( v . into_bytes ( ) )
406+ } ) ? ;
401407
402- let crate_list =
403- format ! ( "window.ALL_CRATES = [{}];" , krates. iter( ) . map( |k| format!( "\" {}\" " , k) ) . join( "," ) ) ;
404- write_crate ( "crates.js" , & crate_list) ?;
408+ write_crate ( "crates.js" , & || {
409+ let krates = krates. iter ( ) . map ( |k| format ! ( "\" {}\" " , k) ) . join ( "," ) ;
410+ Ok ( format ! ( "window.ALL_CRATES = [{}];" , krates) . into_bytes ( ) )
411+ } ) ?;
405412
406413 if options. enable_index_page {
407414 if let Some ( index_page) = options. index_page . clone ( ) {
0 commit comments