From 815f5bbcc53dbb40c11127f26080e0ad9b7dc935 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 6 Apr 2023 14:53:29 -0700 Subject: [PATCH 1/5] rustdoc: clean up JS * Stop checking `func` in `onEach`. It's always hard-coded right at the call site, so there's no point. * Use the ternary operator in a few spots where it makes sense. * No point in making `onEach` store `arr.length` in a variable if it's only used once anyway. --- src/librustdoc/html/static/js/main.js | 10 ++-------- src/librustdoc/html/static/js/settings.js | 8 ++------ src/librustdoc/html/static/js/storage.js | 19 +++++-------------- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 45c0360a49ea6..56ee4c1510e8f 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -332,13 +332,7 @@ function preLoadCss(cssUrl) { }; function getPageId() { - if (window.location.hash) { - const tmp = window.location.hash.replace(/^#/, ""); - if (tmp.length > 0) { - return tmp; - } - } - return null; + return window.location.hash.replace(/^#/, ""); } const toggleAllDocsId = "toggle-all-docs"; @@ -707,7 +701,7 @@ function preLoadCss(cssUrl) { }); const pageId = getPageId(); - if (pageId !== null) { + if (pageId !== "") { expandSection(pageId); } }()); diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js index 1cd552e7f25b7..ebbe6c1ca9a24 100644 --- a/src/librustdoc/html/static/js/settings.js +++ b/src/librustdoc/html/static/js/settings.js @@ -86,12 +86,8 @@ if (settingId === "theme") { const useSystem = getSettingValue("use-system-theme"); if (useSystem === "true" || settingValue === null) { - if (useSystem !== "false") { - settingValue = "system preference"; - } else { - // This is the default theme. - settingValue = "light"; - } + // "light" is the default theme + settingValue = useSystem === "false" ? "light" : "system preference"; } } if (settingValue !== null && settingValue !== "null") { diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js index 8d82b5b78edbb..9ce09cd502e61 100644 --- a/src/librustdoc/html/static/js/storage.js +++ b/src/librustdoc/html/static/js/storage.js @@ -53,10 +53,9 @@ function removeClass(elem, className) { * @param {boolean} [reversed] - Whether to iterate in reverse */ function onEach(arr, func, reversed) { - if (arr && arr.length > 0 && func) { + if (arr && arr.length > 0) { if (reversed) { - const length = arr.length; - for (let i = length - 1; i >= 0; --i) { + for (let i = arr.length - 1; i >= 0; --i) { if (func(arr[i])) { return true; } @@ -150,26 +149,18 @@ const updateTheme = (function() { * … dictates that it should be. */ function updateTheme() { - const use = (theme, saveTheme) => { - switchTheme(theme, saveTheme); - }; - // maybe the user has disabled the setting in the meantime! if (getSettingValue("use-system-theme") !== "false") { const lightTheme = getSettingValue("preferred-light-theme") || "light"; const darkTheme = getSettingValue("preferred-dark-theme") || "dark"; - if (mql.matches) { - use(darkTheme, true); - } else { - // prefers a light theme, or has no preference - use(lightTheme, true); - } + // use light theme if user prefers it, or has no preference + switchTheme(mql.matches ? darkTheme : lightTheme, true); // note: we save the theme so that it doesn't suddenly change when // the user disables "use-system-theme" and reloads the page or // navigates to another page } else { - use(getSettingValue("theme"), false); + switchTheme(getSettingValue("theme"), false); } } From 5cad51c0c5a21c94bb119277131ac4b60576041a Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 6 Apr 2023 20:25:07 -0700 Subject: [PATCH 2/5] rustdoc: add test and bug fix for theme defaults --- src/librustdoc/html/static/js/storage.js | 1 + tests/rustdoc-gui/theme-defaults.goml | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/rustdoc-gui/theme-defaults.goml diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js index 8d82b5b78edbb..67d3981ce07cd 100644 --- a/src/librustdoc/html/static/js/storage.js +++ b/src/librustdoc/html/static/js/storage.js @@ -158,6 +158,7 @@ const updateTheme = (function() { if (getSettingValue("use-system-theme") !== "false") { const lightTheme = getSettingValue("preferred-light-theme") || "light"; const darkTheme = getSettingValue("preferred-dark-theme") || "dark"; + updateLocalStorage("use-system-theme", "true"); if (mql.matches) { use(darkTheme, true); diff --git a/tests/rustdoc-gui/theme-defaults.goml b/tests/rustdoc-gui/theme-defaults.goml new file mode 100644 index 0000000000000..d5ed536b1a962 --- /dev/null +++ b/tests/rustdoc-gui/theme-defaults.goml @@ -0,0 +1,24 @@ +// Ensure that the theme picker always starts with the actual defaults. +goto: "file://" + |DOC_PATH| + "/test_docs/index.html" +click: "#settings-menu" +wait-for: "#theme-system-preference" +assert: "#theme-system-preference:checked" +assert: "#preferred-light-theme-light:checked" +assert: "#preferred-dark-theme-dark:checked" +assert-false: "#preferred-dark-theme-ayu:checked" + +// Test legacy migration from old theme setup without system-preference matching. +// See https://github.com/rust-lang/rust/pull/77809#issuecomment-707875732 +local-storage: { + "rustdoc-preferred-light-theme": null, + "rustdoc-preferred-dark-theme": null, + "rustdoc-use-system-theme": null, + "rustdoc-theme": "ayu" +} +goto: "file://" + |DOC_PATH| + "/test_docs/index.html" +click: "#settings-menu" +wait-for: "#theme-system-preference" +assert: "#theme-system-preference:checked" +assert: "#preferred-light-theme-light:checked" +assert-false: "#preferred-dark-theme-dark:checked" +assert: "#preferred-dark-theme-ayu:checked" From 7e9e91c3d395941b21dd1c791ff936ae44b4d45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Bethune?= Date: Fri, 7 Apr 2023 23:49:20 +0200 Subject: [PATCH 3/5] Fix wrong type in docs: i16 -> u16 @rustbot label +A-docs r? docs --- library/core/src/num/shells/u16.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/num/shells/u16.rs b/library/core/src/num/shells/u16.rs index b203806f46005..7394977e5078a 100644 --- a/library/core/src/num/shells/u16.rs +++ b/library/core/src/num/shells/u16.rs @@ -1,4 +1,4 @@ -//! Redundant constants module for the [`i16` primitive type][i16]. +//! Redundant constants module for the [`u16` primitive type][u16]. //! //! New code should use the associated constants directly on the primitive type. From f8b62ff535ec1957e3a3b36bf7b0debc22ef447c Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 7 Apr 2023 15:24:08 -0700 Subject: [PATCH 4/5] Remove myself from reviewers list I'm going to be unable to review for the next few weeks, so I'm removing myself from the review queue. Once I'm back and able to review again, I'll add myself back to the list. --- triagebot.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/triagebot.toml b/triagebot.toml index 2d7be7d12734a..5f4de0562f89f 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -470,8 +470,8 @@ cc = ["@rust-lang/style"] [mentions."Cargo.lock"] message = """ -These commits modify the `Cargo.lock` file. Random changes to `Cargo.lock` can be introduced when switching branches and rebasing PRs. -This was probably unintentional and should be reverted before this PR is merged. +These commits modify the `Cargo.lock` file. Random changes to `Cargo.lock` can be introduced when switching branches and rebasing PRs. +This was probably unintentional and should be reverted before this PR is merged. If this was intentional then you can ignore this comment. """ @@ -499,7 +499,6 @@ compiler-team = [ ] compiler-team-contributors = [ "@compiler-errors", - "@eholk", "@jackh726", "@TaKO8Ki", "@WaffleLapkin", From 2b36f5a40f523b563e04986126dedb86eb4a9470 Mon Sep 17 00:00:00 2001 From: Krishna Ramasimha <82328083+KittyBorgX@users.noreply.github.com> Date: Sat, 8 Apr 2023 13:49:00 +0530 Subject: [PATCH 5/5] Fix a typo in `config.example.toml` --- config.example.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.example.toml b/config.example.toml index 5ef83760aed2d..15c6bc0f12376 100644 --- a/config.example.toml +++ b/config.example.toml @@ -16,7 +16,7 @@ # Use different pre-set defaults than the global defaults. # # See `src/bootstrap/defaults` for more information. -# Note that this has no default value (x.py uses the defaults in `config.toml.example`). +# Note that this has no default value (x.py uses the defaults in `config.example.toml`). #profile = # Keeps track of the last version of `x.py` used.