diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 4458eea95f3e1..2a0ee28e4ba37 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use crate::externalfiles::ExternalHtml; use crate::html::escape::Escape; use crate::html::format::{Buffer, Print}; -use crate::html::render::{ensure_trailing_slash, StylePath}; +use crate::html::render::StylePath; #[derive(Clone)] crate struct Layout { @@ -134,22 +134,20 @@ crate fn render( root_path = page.root_path, css_class = page.css_class, logo = { - let p = format!("{}{}", page.root_path, layout.krate); - let p = ensure_trailing_slash(&p); if layout.logo.is_empty() { format!( - "\ + "\ ", - path = p, + path = page.root_path, static_root_path = static_root_path, suffix = page.resource_suffix ) } else { format!( - "\ + "\
logo
", - p, layout.logo + page.root_path, layout.logo ) } }, diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 03e091297e5b6..fa0e71be162f7 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -596,6 +596,21 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { &style_files, ); self.shared.fs.write(&settings_file, v.as_bytes())?; + + // HACK(ThePuzzlemaker, #81031): As suggested by jynelson, we create a + // redirect page in the parent directory (below the specific crate dir, + // i.e. target/doc or similar) redirecting to that crate's index. This + // way, the last crate compiled will be the one redirected to. Assuming + // you never document examples, and that if you document a binary, you + // want it to take precedence over a library present there, this works + // to have the logo redirect to the "main crate" (the one that would be + // opened by cargo doc --open), without having to add a new rustdoc + // flag and cargo integration. + + let v = + layout::redirect(Path::new(&*krate.name.as_str()).join("index.html").to_str().unwrap()); + self.shared.fs.write(&self.dst.join("logo-redirect.html"), v.as_bytes())?; + Ok(()) } diff --git a/src/test/rustdoc/keyword.rs b/src/test/rustdoc/keyword.rs index 25e8b7912e772..7997e86eb4de3 100644 --- a/src/test/rustdoc/keyword.rs +++ b/src/test/rustdoc/keyword.rs @@ -8,7 +8,7 @@ // @has foo/keyword.match.html '//a[@class="keyword"]' 'match' // @has foo/keyword.match.html '//span[@class="in-band"]' 'Keyword match' // @has foo/keyword.match.html '//section[@id="main"]//div[@class="docblock"]//p' 'this is a test!' -// @has foo/index.html '//a/@href' '../foo/index.html' +// @has foo/index.html '//a/@href' '../logo-redirect.html' // @!has foo/foo/index.html // @!has-dir foo/foo #[doc(keyword = "match")]