From edae82e5e4b29718ee060b86cffa0d702cabc713 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Mon, 3 Jan 2022 17:35:38 +0800 Subject: [PATCH 01/11] std: Implement try_reserve and try_reserve_exact on PathBuf Signed-off-by: Xuanwo --- library/std/src/path.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 7d401cff591c1..9104ad46fb47c 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -72,6 +72,7 @@ mod tests; use crate::borrow::{Borrow, Cow}; use crate::cmp; +use crate::collections::TryReserveError; use crate::error::Error; use crate::fmt; use crate::fs; @@ -1512,6 +1513,15 @@ impl PathBuf { self.inner.reserve(additional) } + /// Invokes [`try_reserve`] on the underlying instance of [`OsString`]. + /// + /// [`try_reserve`]: OsString::try_reserve + #[unstable(feature = "try_reserve_2", issue = "91789")] + #[inline] + pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> { + self.inner.try_reserve(additional) + } + /// Invokes [`reserve_exact`] on the underlying instance of [`OsString`]. /// /// [`reserve_exact`]: OsString::reserve_exact @@ -1521,6 +1531,15 @@ impl PathBuf { self.inner.reserve_exact(additional) } + /// Invokes [`try_reserve_exact`] on the underlying instance of [`OsString`]. + /// + /// [`try_reserve_exact`]: OsString::try_reserve_exact + #[unstable(feature = "try_reserve_2", issue = "91789")] + #[inline] + pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> { + self.inner.try_reserve_exact(additional) + } + /// Invokes [`shrink_to_fit`] on the underlying instance of [`OsString`]. /// /// [`shrink_to_fit`]: OsString::shrink_to_fit From 495c7b31aaef783c583d2a0304002367df0a1474 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Fri, 21 Jan 2022 09:41:13 +0200 Subject: [PATCH 02/11] Fix STD compilation for the ESP-IDF target --- library/std/src/sys/unix/fs.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index f8deda93fe2a7..ad656582a0970 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -1448,8 +1448,8 @@ pub fn chroot(dir: &Path) -> io::Result<()> { pub use remove_dir_impl::remove_dir_all; -// Fallback for REDOX -#[cfg(target_os = "redox")] +// Fallback for REDOX and ESP-IDF +#[cfg(any(target_os = "redox", target_os = "espidf"))] mod remove_dir_impl { pub use crate::sys_common::fs::remove_dir_all; } @@ -1573,7 +1573,11 @@ mod remove_dir_impl { } // Modern implementation using openat(), unlinkat() and fdopendir() -#[cfg(not(any(all(target_os = "macos", target_arch = "x86_64"), target_os = "redox")))] +#[cfg(not(any( + all(target_os = "macos", target_arch = "x86_64"), + target_os = "redox", + target_os = "espidf" +)))] mod remove_dir_impl { use super::{cstr, lstat, Dir, DirEntry, InnerReadDir, ReadDir}; use crate::ffi::CStr; From 91b9b6adfb6c585a7bf6cd4a47adbd1f20bd5c73 Mon Sep 17 00:00:00 2001 From: Matthew James Kraai Date: Fri, 21 Jan 2022 19:47:35 -0800 Subject: [PATCH 03/11] Fix link to CVE-2022-21658 --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index f44291c1fa302..aae2a66965014 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -7,7 +7,7 @@ Version 1.58.1 (2022-01-19) * [Fix wrong error message displayed when some imports are missing][91254] * [Fix rustfmt not formatting generated files from stdin][92912] -[CVE-2022-21658]: https://www.cve.org/CVERecord?id=CVE-2022-21658] +[CVE-2022-21658]: https://www.cve.org/CVERecord?id=CVE-2022-21658 [91254]: https://github.com/rust-lang/rust/pull/91254 [92912]: https://github.com/rust-lang/rust/pull/92912 [clippy/8075]: https://github.com/rust-lang/rust-clippy/pull/8075 From 9f30dd9cbc3918e650fb4367ccd8f47335f6c5a3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 22 Jan 2022 19:43:25 +0100 Subject: [PATCH 04/11] Remove unneeded cursor pointer rule on mobile sidebar --- src/librustdoc/html/static/css/rustdoc.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 2c937aa0ec928..db29fa7be7c86 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1868,7 +1868,6 @@ details.rustdoc-toggle[open] > summary.hideme::after { position: sticky; z-index: 10; font-size: 2rem; - cursor: pointer; height: 45px; width: 100%; left: 0; From 9c3ffd7681fca17e29ef90b8e91d6fe26b0a8b3f Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Sun, 23 Jan 2022 09:06:44 +0000 Subject: [PATCH 05/11] adjust sidebar link brightness --- src/librustdoc/html/static/css/themes/ayu.css | 3 +++ src/librustdoc/html/static/css/themes/dark.css | 3 +++ src/librustdoc/html/static/css/themes/light.css | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index 69097b81b9f1c..5e08d9732d484 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -221,6 +221,9 @@ pre.rust a, body.source .example-wrap pre.rust a { background: #333; } +.sidebar a { + color: #53b1db; +} details.rustdoc-toggle > summary.hideme > span, details.rustdoc-toggle > summary::before, diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 39165b2fc058f..057ba92136d1c 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -182,6 +182,9 @@ a.test-arrow { body.source .example-wrap pre.rust a { background: #333; } +.sidebar a { + color: #fdbf35; +} details.rustdoc-toggle > summary.hideme > span, details.rustdoc-toggle > summary::before, diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 448c9ac603c82..1b6188aaa3b6b 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -179,6 +179,9 @@ a.test-arrow { body.source .example-wrap pre.rust a { background: #eee; } +.sidebar a { + color: #356da4; +} details.rustdoc-toggle > summary.hideme > span, details.rustdoc-toggle > summary::before, From a0748d9436e1e0b674dfd98801058911489879c9 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Sun, 23 Jan 2022 10:43:06 +0000 Subject: [PATCH 06/11] tweak all sidebar colours --- src/librustdoc/html/static/css/themes/ayu.css | 23 +++++++++++++++++ .../html/static/css/themes/dark.css | 25 ++++++++++++++++--- .../html/static/css/themes/light.css | 22 ++++++++++++++++ src/test/rustdoc-gui/anchors.goml | 2 +- 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index 5e08d9732d484..1aefe893f16a0 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -191,6 +191,10 @@ pre, .rustdoc.source .example-wrap { color: #a37acc; } +.sidebar a { color: #53b1db; } +.sidebar a.current.type { color: #53b1db; } +.sidebar a.current.associatedtype { color: #53b1db; } + pre.rust .comment { color: #788797; } pre.rust .doccomment { color: #a1ac88; } @@ -496,6 +500,25 @@ a.result-static:focus {} a.result-primitive:focus {} a.result-keyword:focus {} +.sidebar a.current.enum {} +.sidebar a.current.struct {} +.sidebar a.current.foreigntype {} +.sidebar a.current.attr, +.sidebar a.current.derive, +.sidebar a.current.macro {} +.sidebar a.current.union {} +.sidebar a.current.constant +.sidebar a.current.static {} +.sidebar a.current.primitive {} +.sidebar a.current.externcrate +.sidebar a.current.mod {} +.sidebar a.current.trait {} +.sidebar a.current.traitalias {} +.sidebar a.current.fn, +.sidebar a.current.method, +.sidebar a.current.tymethod {} +.sidebar a.current.keyword {} + @media (max-width: 700px) { .sidebar-menu { background-color: #14191f; diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 057ba92136d1c..7b887f91c25d5 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -148,6 +148,28 @@ a.result-keyword:focus { background-color: #884719; } .content .fnname{ color: #2BAB63; } .content span.keyword, .content a.keyword, .block a.current.keyword { color: #D2991D; } +.sidebar a { color: #fdbf35; } +.sidebar a.current.enum { color: #12ece2; } +.sidebar a.current.struct { color: #12ece2; } +.sidebar a.current.type { color: #12ece2; } +.sidebar a.current.associatedtype { color: #fdbf35; } +.sidebar a.current.foreigntype { color: #12ece2; } +.sidebar a.current.attr, +.sidebar a.current.derive, +.sidebar a.current.macro { color: #0be900; } +.sidebar a.current.union { color: #12ece2; } +.sidebar a.current.constant +.sidebar a.current.static { color: #fdbf35; } +.sidebar a.current.primitive { color: #12ece2; } +.sidebar a.current.externcrate +.sidebar a.current.mod { color: #fdbf35; } +.sidebar a.current.trait { color: #cca7ff; } +.sidebar a.current.traitalias { color: #cca7ff; } +.sidebar a.current.fn, +.sidebar a.current.method, +.sidebar a.current.tymethod { color: #32d479; } +.sidebar a.current.keyword { color: #fdbf35; } + pre.rust .comment { color: #8d8d8b; } pre.rust .doccomment { color: #8ca375; } @@ -182,9 +204,6 @@ a.test-arrow { body.source .example-wrap pre.rust a { background: #333; } -.sidebar a { - color: #fdbf35; -} details.rustdoc-toggle > summary.hideme > span, details.rustdoc-toggle > summary::before, diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 1b6188aaa3b6b..cf0d586d954a0 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -148,6 +148,28 @@ a.result-keyword:focus { background-color: #afc6e4; } .content .fnname { color: #AD7C37; } .content span.keyword, .content a.keyword, .block a.current.keyword { color: #3873AD; } +.sidebar a { color: #356da4; } +.sidebar a.current.enum { color: #a63283; } +.sidebar a.current.struct { color: #a63283; } +.sidebar a.current.type { color: #a63283; } +.sidebar a.current.associatedtype { color: #356da4; } +.sidebar a.current.foreigntype { color: #356da4; } +.sidebar a.current.attr, +.sidebar a.current.derive, +.sidebar a.current.macro { color: #067901; } +.sidebar a.current.union { color: #a63283; } +.sidebar a.current.constant +.sidebar a.current.static { color: #356da4; } +.sidebar a.current.primitive { color: #a63283; } +.sidebar a.current.externcrate +.sidebar a.current.mod { color: #356da4; } +.sidebar a.current.trait { color: #6849c3; } +.sidebar a.current.traitalias { color: #4b349e; } +.sidebar a.current.fn, +.sidebar a.current.method, +.sidebar a.current.tymethod { color: #32d479; } +.sidebar a.current.keyword { color: #356da4; } + nav.main .current { border-top-color: #000; border-bottom-color: #000; diff --git a/src/test/rustdoc-gui/anchors.goml b/src/test/rustdoc-gui/anchors.goml index 2d48d21dc1b05..26e4503a5d086 100644 --- a/src/test/rustdoc-gui/anchors.goml +++ b/src/test/rustdoc-gui/anchors.goml @@ -20,7 +20,7 @@ assert-css: (".srclink", {"text-decoration": "underline solid rgb(56, 115, 173)" assert-css: ("#top-doc-prose-title", {"color": "rgb(0, 0, 0)"}) -assert-css: (".sidebar a", {"color": "rgb(56, 115, 173)"}) +assert-css: (".sidebar a", {"color": "rgb(53, 109, 164)"}) assert-css: (".in-band a", {"color": "rgb(0, 0, 0)"}) // We move the cursor over the "Implementations" title so the anchor is displayed. From f00b02bb69676d852d5267f859ed894bbfa6cc5c Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Sun, 23 Jan 2022 11:05:04 +0000 Subject: [PATCH 07/11] remove duplicate rule --- src/librustdoc/html/static/css/themes/ayu.css | 3 --- src/librustdoc/html/static/css/themes/light.css | 3 --- 2 files changed, 6 deletions(-) diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index 1aefe893f16a0..de75ca5acf7af 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -225,9 +225,6 @@ pre.rust a, body.source .example-wrap pre.rust a { background: #333; } -.sidebar a { - color: #53b1db; -} details.rustdoc-toggle > summary.hideme > span, details.rustdoc-toggle > summary::before, diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index cf0d586d954a0..ec8cac7fa6ef7 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -201,9 +201,6 @@ a.test-arrow { body.source .example-wrap pre.rust a { background: #eee; } -.sidebar a { - color: #356da4; -} details.rustdoc-toggle > summary.hideme > span, details.rustdoc-toggle > summary::before, From d889a4ebac0320d1f68f25d1bf00d7ae659e5a13 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 23 Jan 2022 18:03:07 +0100 Subject: [PATCH 08/11] Fix brief appearance of rust logo in the sidebar --- src/librustdoc/html/static/css/rustdoc.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 2c937aa0ec928..6a87596288a39 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -398,7 +398,7 @@ nav.sub { } .source .sidebar > *:not(:first-child) { - transition: opacity 0.5s, visibility 0.2s; + transition: opacity 0.5s; opacity: 0; visibility: hidden; } From ca3d0e2316f8d9f0e3b8b6a5285a94ec6e6c60ff Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Sun, 23 Jan 2022 19:26:07 +0000 Subject: [PATCH 09/11] update tests --- src/test/rustdoc-gui/sidebar.goml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/rustdoc-gui/sidebar.goml b/src/test/rustdoc-gui/sidebar.goml index c7abe896be1d1..ae198e4174293 100644 --- a/src/test/rustdoc-gui/sidebar.goml +++ b/src/test/rustdoc-gui/sidebar.goml @@ -9,7 +9,7 @@ assert-text: (".sidebar > .location", "Crate test_docs") // In modules, we only have one "location" element. assert-count: (".sidebar .location", 1) assert-text: ("#all-types", "All Items") -assert-css: ("#all-types", {"color": "rgb(56, 115, 173)"}) +assert-css: ("#all-types", {"color": "rgb(53, 109, 164)"}) // We check that we have the crates list and that the "current" on is "test_docs". assert-text: (".sidebar-elems .crate > ul > li > a.current", "test_docs") // And we're also supposed to have the list of items in the current module. @@ -38,7 +38,7 @@ assert-property: ("html", {"scrollTop": "0"}) // We now go back to the crate page to click on the "lib2" crate link. goto: file://|DOC_PATH|/test_docs/index.html -assert-css: (".sidebar-elems .crate > ul > li:first-child > a", {"color": "rgb(56, 115, 173)"}) +assert-css: (".sidebar-elems .crate > ul > li:first-child > a", {"color": "rgb(53, 109, 164)"}) click: ".sidebar-elems .crate > ul > li:first-child > a" // PAGE: lib2/index.html From bc8ef4cb661eb9b4cacb7b3160837342f8f9ab3e Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sun, 23 Jan 2022 12:55:31 -0800 Subject: [PATCH 10/11] rustdoc: fix bump down typing search on Safari --- src/librustdoc/html/templates/page.html | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index 3325515bef606..baadd3c27b446 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -117,6 +117,7 @@

{#- -#}
{#- -#}
{#- -#} + {#- This empty span is a hacky fix for Safari - See #93184 -#} Date: Sun, 23 Jan 2022 13:04:17 -0800 Subject: [PATCH 11/11] Update theme on pageshow event When a user goes forward or back, the page may be rendered from the back/forward cache (https://web.dev/bfcache/) rather than from scratch. If they have changed theme in the meantime, that means seeing an incorrect theme on the page they went forward or back to. The `pageshow` event fires on such navigations, so we can update the theme based on that event. --- src/librustdoc/html/static/js/storage.js | 31 +++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js index 2394df4c715d4..06bb34eb11573 100644 --- a/src/librustdoc/html/static/js/storage.js +++ b/src/librustdoc/html/static/js/storage.js @@ -216,6 +216,15 @@ var updateSystemTheme = (function() { }; })(); +function switchToSavedTheme() { + switchTheme( + window.currentTheme, + window.mainTheme, + getSettingValue("theme") || "light", + false + ); +} + if (getSettingValue("use-system-theme") !== "false" && window.matchMedia) { // update the preferred dark theme if the user is already using a dark theme // See https://github.com/rust-lang/rust/pull/77809#issuecomment-707875732 @@ -228,10 +237,20 @@ if (getSettingValue("use-system-theme") !== "false" && window.matchMedia) { // call the function to initialize the theme at least once! updateSystemTheme(); } else { - switchTheme( - window.currentTheme, - window.mainTheme, - getSettingValue("theme") || "light", - false - ); + switchToSavedTheme(); } + +// If we navigate away (for example to a settings page), and then use the back or +// forward button to get back to a page, the theme may have changed in the meantime. +// But scripts may not be re-loaded in such a case due to the bfcache +// (https://web.dev/bfcache/). The "pageshow" event triggers on such navigations. +// Use that opportunity to update the theme. +// We use a setTimeout with a 0 timeout here to put the change on the event queue. +// For some reason, if we try to change the theme while the `pageshow` event is +// running, it sometimes fails to take effect. The problem manifests on Chrome, +// specifically when talking to a remote website with no caching. +window.addEventListener("pageshow", function(ev) { + if (ev.persisted) { + setTimeout(switchToSavedTheme, 0); + } +});