From d1f5f72453af1b54ecb610d6c02141dbd5dd1b7d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 22 Aug 2025 15:32:05 +0200 Subject: [PATCH 1/3] Strengthen GUI tests --- gui-tests/sidebar.goml | 5 +++-- gui-tests/theme.goml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gui-tests/sidebar.goml b/gui-tests/sidebar.goml index 760ac09fa..c9bf3f87e 100644 --- a/gui-tests/sidebar.goml +++ b/gui-tests/sidebar.goml @@ -9,6 +9,7 @@ assert-position: (".rustdoc .sidebar", {"y": |topbar_height|, "x": 0}) // We check the same in "mobile mode". set-window-size: (600, 1000) +wait-for-css-false: (".rustdoc .mobile-topbar", {"display": "none"}) assert-position: (".rustdoc .mobile-topbar", {"y": |topbar_height|, "x": 0}) // We check when the sidebar is shown now. click: ".rustdoc .mobile-topbar .sidebar-menu-toggle" @@ -27,8 +28,8 @@ set-window-size: (1000, 1000) wait-for: ".main-heading a.src" click: ".main-heading a.src" -// We wait for the page to load... -wait-for: ".rustdoc.src" +// We wait for the page to load (by waiting for the sidebar to be filled)... +wait-for: "#src-sidebar" // We check that the sidebar has the correct position. assert-position: (".rustdoc .sidebar", {"y": |topbar_height|, "x": 0}) // We expand the sidebar. diff --git a/gui-tests/theme.goml b/gui-tests/theme.goml index 8684cc2cc..2abfc0bfa 100644 --- a/gui-tests/theme.goml +++ b/gui-tests/theme.goml @@ -6,7 +6,7 @@ // the crate page we control the whole page go-to: |DOC_PATH| + "/sysinfo" -set-local-storage: { "rustdoc-theme": null } +set-local-storage: { "rustdoc-theme": "light" } wait-for-css: (".nav-container", { "background-color": "rgb(255, 255, 255)" }) go-to: |DOC_PATH| + "/crate/sysinfo" wait-for-css: ("body", { "background-color": "rgb(255, 255, 255)" }) From fc03d36d638b1e973b92b47ef265caf7bc6327a3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 22 Aug 2025 15:43:30 +0200 Subject: [PATCH 2/3] Update to last rustdoc DOM changes --- gui-tests/sidebar.goml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gui-tests/sidebar.goml b/gui-tests/sidebar.goml index c9bf3f87e..763e18a30 100644 --- a/gui-tests/sidebar.goml +++ b/gui-tests/sidebar.goml @@ -9,13 +9,13 @@ assert-position: (".rustdoc .sidebar", {"y": |topbar_height|, "x": 0}) // We check the same in "mobile mode". set-window-size: (600, 1000) -wait-for-css-false: (".rustdoc .mobile-topbar", {"display": "none"}) -assert-position: (".rustdoc .mobile-topbar", {"y": |topbar_height|, "x": 0}) +wait-for-css-false: ("rustdoc-topbar", {"display": "none"}) +assert-position: ("rustdoc-topbar", {"y": |topbar_height|, "x": 0}) // We check when the sidebar is shown now. -click: ".rustdoc .mobile-topbar .sidebar-menu-toggle" +click: "rustdoc-topbar .sidebar-menu-toggle" wait-for: ".rustdoc .sidebar.shown" // The mobile sidebar is supposed to be under the rustdoc mobile topbar + docs.rs topbar. -store-size: (".rustdoc .mobile-topbar", {"height": rustdoc_topbar_height}) +store-size: ("rustdoc-topbar", {"height": rustdoc_topbar_height}) assert-position: (".rustdoc .sidebar.shown", { "y": |topbar_height| + |rustdoc_topbar_height|, "x": 0, From fcecde1b420148d15678b7e1a57e9e6a0c6eecd1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 22 Aug 2025 16:36:58 +0200 Subject: [PATCH 3/3] Overload new source page sidebar button position --- src/utils/rustc_version.rs | 5 ++++- src/web/statics.rs | 6 ++++++ templates/style/rustdoc-2025-08-20.scss | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 templates/style/rustdoc-2025-08-20.scss diff --git a/src/utils/rustc_version.rs b/src/utils/rustc_version.rs index 0d632b851..8a9194dd5 100644 --- a/src/utils/rustc_version.rs +++ b/src/utils/rustc_version.rs @@ -44,8 +44,11 @@ pub(crate) fn parse_rustc_date>(version: S) -> Result { /// generate this version of this crate. pub fn get_correct_docsrs_style_file(version: &str) -> Result { let date = parse_rustc_date(version)?; + // This is the date where https://github.com/rust-lang/rust/pull/144476 was merged. + if NaiveDate::from_ymd_opt(2025, 8, 20).unwrap() < date { + Ok("rustdoc-2025-08-20.css".to_owned()) // This is the date where https://github.com/rust-lang/rust/pull/91356 was merged. - if NaiveDate::from_ymd_opt(2021, 12, 5).unwrap() < date { + } else if NaiveDate::from_ymd_opt(2021, 12, 5).unwrap() < date { // If this is the new rustdoc layout, we need the newer docs.rs CSS file. Ok("rustdoc-2021-12-05.css".to_owned()) } else { diff --git a/src/web/statics.rs b/src/web/statics.rs index 36a820462..5b02fefac 100644 --- a/src/web/statics.rs +++ b/src/web/statics.rs @@ -16,6 +16,8 @@ const STYLE_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/style.css")); const RUSTDOC_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/rustdoc.css")); const RUSTDOC_2021_12_05_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/rustdoc-2021-12-05.css")); +const RUSTDOC_2025_08_20_CSS: &str = + include_str!(concat!(env!("OUT_DIR"), "/rustdoc-2025-08-20.css")); fn build_static_css_response(content: &'static str) -> impl IntoResponse { ( @@ -67,6 +69,10 @@ pub(crate) fn build_static_router() -> AxumRouter { "/rustdoc-2021-12-05.css", get_static(|| async { build_static_css_response(RUSTDOC_2021_12_05_CSS) }), ) + .route( + "/rustdoc-2025-08-20.css", + get_static(|| async { build_static_css_response(RUSTDOC_2025_08_20_CSS) }), + ) .fallback_service( get_service(ServeDir::new("static").fallback(ServeDir::new("vendor"))) .layer(middleware::from_fn(set_needed_static_headers)) diff --git a/templates/style/rustdoc-2025-08-20.scss b/templates/style/rustdoc-2025-08-20.scss new file mode 100644 index 000000000..f887447dc --- /dev/null +++ b/templates/style/rustdoc-2025-08-20.scss @@ -0,0 +1,10 @@ +@import "rustdoc-2021-12-05"; + +// This file is needed to overload the previous docs.rs style. It is added into crates generated +// using rustdoc after https://github.com/rust-lang/rust/pull/144476 has been merged. + +.rustdoc.src { + #sidebar-button { + top: calc(8px + #{$top-navbar-height}); + } +}