about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustdoc/html/layout.rs9
-rw-r--r--src/librustdoc/html/render/context.rs2
-rw-r--r--src/librustdoc/html/render/print_item.rs2
-rw-r--r--src/librustdoc/html/render/write_shared.rs9
-rw-r--r--src/librustdoc/html/static_files.rs4
-rw-r--r--src/test/rustdoc/static-root-path.rs6
6 files changed, 19 insertions, 13 deletions
diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs
index 087e9219b67..c1b3526eb45 100644
--- a/src/librustdoc/html/layout.rs
+++ b/src/librustdoc/html/layout.rs
@@ -35,15 +35,18 @@ pub(crate) struct Page<'a> {
 }
 
 impl<'a> Page<'a> {
-    pub(crate) fn get_static_root_path(&self) -> &str {
-        self.static_root_path.unwrap_or(self.root_path)
+    pub(crate) fn get_static_root_path(&self) -> String {
+        match self.static_root_path {
+            Some(s) => s.to_string(),
+            None => format!("{}{}", self.root_path, "static.files/"),
+        }
     }
 }
 
 #[derive(Template)]
 #[template(path = "page.html")]
 struct PageLayout<'a> {
-    static_root_path: &'a str,
+    static_root_path: String,
     page: &'a Page<'a>,
     layout: &'a Layout,
 
diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs
index 5263d0d2232..51843a505f7 100644
--- a/src/librustdoc/html/render/context.rs
+++ b/src/librustdoc/html/render/context.rs
@@ -636,7 +636,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
                      <link rel=\"stylesheet\" type=\"text/css\" \
                          href=\"{static_root_path}{settings_css}\">\
                      <script defer src=\"{static_root_path}{settings_js}\"></script>",
-                    static_root_path = page.static_root_path.unwrap_or(""),
+                    static_root_path = page.get_static_root_path(),
                     settings_css = static_files::STATIC_FILES.settings_css,
                     settings_js = static_files::STATIC_FILES.settings_js,
                 )
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index 713c5d1bcb6..2920a81e5b2 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -147,7 +147,7 @@ pub(super) fn print_item(
     };
 
     let item_vars = ItemVars {
-        static_root_path: page.get_static_root_path(),
+        static_root_path: &page.get_static_root_path(),
         clipboard_svg: &static_files::STATIC_FILES.clipboard_svg,
         typ,
         name: item.name.as_ref().unwrap().as_str(),
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index 723c502c584..07d139e9e12 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -24,7 +24,8 @@ use crate::{try_err, try_none};
 ///    URL if the contents change, so they are safe to cache with the
 ///    `Cache-Control: immutable` directive. They are written under the static.files/
 ///    directory and are written when --emit-type is empty (default) or contains
-///    "toolchain-specific".
+///    "toolchain-specific". If using the --static-root-path flag, it should point
+///    to a URL path prefix where each of these filenames can be fetched.
 ///  - Invocation specific files. These are generated based on the crate(s) being
 ///    documented. Their filenames need to be predictable without knowing their
 ///    contents, so they do not include a hash in their filename and are not safe to
@@ -85,8 +86,10 @@ pub(super) fn write_shared(
 
     if options.emit.is_empty() || options.emit.contains(&EmitType::Toolchain) {
         for f in static_files::STATIC_FILES_LIST {
-            let filename = static_files::static_filename(f.filename, f.bytes);
-            cx.shared.fs.write(cx.dst.join(filename), f.minified())?;
+            let filename = cx.dst.join(
+                Path::new("static.files/").join(static_files::static_filename(f.filename, f.bytes)),
+            );
+            cx.shared.fs.write(filename, f.minified())?;
         }
     }
 
diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs
index 7b89dc8cd9f..c922890bc0b 100644
--- a/src/librustdoc/html/static_files.rs
+++ b/src/librustdoc/html/static_files.rs
@@ -5,7 +5,7 @@
 
 use rustc_data_structures::fx::FxHasher;
 use std::hash::Hasher;
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
 use std::{fmt, str};
 
 pub(crate) struct StaticFile {
@@ -51,7 +51,7 @@ pub(crate) fn suffix_path(filename: &str, suffix: &str) -> PathBuf {
 
 pub(crate) fn static_filename(filename: &str, contents: &[u8]) -> PathBuf {
     let filename = filename.rsplit("/").next().unwrap();
-    Path::new("static.files").join(suffix_path(filename, &static_suffix(contents)))
+    suffix_path(filename, &static_suffix(contents))
 }
 
 fn static_suffix(bytes: &[u8]) -> String {
diff --git a/src/test/rustdoc/static-root-path.rs b/src/test/rustdoc/static-root-path.rs
index 04de52c0df0..86928b0fb0a 100644
--- a/src/test/rustdoc/static-root-path.rs
+++ b/src/test/rustdoc/static-root-path.rs
@@ -1,18 +1,18 @@
 // compile-flags:-Z unstable-options --static-root-path /cache/
 
 // @has static_root_path/struct.SomeStruct.html
-// @matchesraw - '"/cache/static.files/main-'
+// @matchesraw - '"/cache/main-'
 // @!matchesraw - '"\.\./main'
 // @matchesraw - 'data-root-path="\.\./"'
 // @!matchesraw - '"/cache/search-index\.js"'
 pub struct SomeStruct;
 
 // @has src/static_root_path/static-root-path.rs.html
-// @matchesraw - '"/cache/static.files/source-script-'
+// @matchesraw - '"/cache/source-script-'
 // @!matchesraw - '"\.\./\.\./source-script'
 // @matchesraw - '"\.\./\.\./source-files.js"'
 // @!matchesraw - '"/cache/source-files\.js"'
 
 // @has settings.html
-// @matchesraw - '/cache/static.files/settings-'
+// @matchesraw - '/cache/settings-'
 // @!matchesraw - '\../settings'