Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #110073

Closed
wants to merge 10 commits into from
2 changes: 0 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2908,7 +2908,6 @@ dependencies = [
"anyhow",
"clap 4.2.1",
"fs-err",
"rustc-hash",
"rustdoc-json-types",
"serde",
"serde_json",
Expand Down Expand Up @@ -5539,7 +5538,6 @@ dependencies = [
name = "rustdoc-json-types"
version = "0.1.0"
dependencies = [
"rustc-hash",
"serde",
"serde_json",
]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/num/shells/u16.rs
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ itertools = "0.10.1"
minifier = "0.2.2"
once_cell = "1.10.0"
regex = "1"
rustdoc-json-types = { path = "../rustdoc-json-types" }
rustdoc-json-types = { path = "../rustdoc-json-types", features = ["rustc_hash"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
smallvec = "1.8.1"
Expand Down
10 changes: 2 additions & 8 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -707,7 +701,7 @@ function preLoadCss(cssUrl) {
});

const pageId = getPageId();
if (pageId !== null) {
if (pageId !== "") {
expandSection(pageId);
}
}());
Expand Down
8 changes: 2 additions & 6 deletions src/librustdoc/html/static/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
20 changes: 6 additions & 14 deletions src/librustdoc/html/static/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -150,26 +149,19 @@ 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";
updateLocalStorage("use-system-theme", "true");

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);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,11 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
let index = (*self.index).clone().into_inner();

debug!("Constructing Output");
// This needs to be the default HashMap for compatibility with the public interface for
// rustdoc-json-types
#[allow(rustc::default_hash_types)]
let output = types::Crate {
root: types::Id(format!("0:0:{}", e.name(self.tcx).as_u32())),
crate_version: self.cache.crate_version.clone(),
includes_private: self.cache.document_private,
index: index.into_iter().collect(),
index,
paths: self
.cache
.paths
Expand Down
4 changes: 3 additions & 1 deletion src/rustdoc-json-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ path = "lib.rs"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
rustc-hash = "1.1.0"

[dev-dependencies]
serde_json = "1.0"

[features]
rustc_hash = []
17 changes: 12 additions & 5 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
//! These types are the public API exposed through the `--output-format json` flag. The [`Crate`]
//! struct is the root of the JSON blob and all other items are contained within.

use rustc_hash::FxHashMap;
#![cfg_attr(feature = "rustc_hash", feature(rustc_private))]
#[cfg(feature = "rustc_hash")]
extern crate rustc_hash;
#[cfg(feature = "rustc_hash")]
use rustc_hash::FxHashMap as HashMap;
#[cfg(not(feature = "rustc_hash"))]
use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use std::path::PathBuf;

Expand All @@ -23,11 +30,11 @@ pub struct Crate {
pub includes_private: bool,
/// A collection of all items in the local crate as well as some external traits and their
/// items that are referenced locally.
pub index: FxHashMap<Id, Item>,
pub index: HashMap<Id, Item>,
/// Maps IDs to fully qualified paths and other info helpful for generating links.
pub paths: FxHashMap<Id, ItemSummary>,
pub paths: HashMap<Id, ItemSummary>,
/// Maps `crate_id` of items to a crate name and html_root_url if it exists.
pub external_crates: FxHashMap<u32, ExternalCrate>,
pub external_crates: HashMap<u32, ExternalCrate>,
/// A single version number to be used in the future when making backwards incompatible changes
/// to the JSON output.
pub format_version: u32,
Expand Down Expand Up @@ -79,7 +86,7 @@ pub struct Item {
/// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`).
pub docs: Option<String>,
/// This mapping resolves [intra-doc links](https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md) from the docstring to their IDs
pub links: FxHashMap<String, Id>,
pub links: HashMap<String, Id>,
/// Stringified versions of the attributes on this item (e.g. `"#[inline]"`)
pub attrs: Vec<String>,
pub deprecation: Option<Deprecation>,
Expand Down
1 change: 0 additions & 1 deletion src/tools/jsondoclint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
anyhow = "1.0.62"
clap = { version = "4.0.15", features = ["derive"] }
fs-err = "2.8.1"
rustc-hash = "1.1.0"
rustdoc-json-types = { version = "0.1.0", path = "../../rustdoc-json-types" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.85"
28 changes: 14 additions & 14 deletions src/tools/jsondoclint/src/validator/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_hash::FxHashMap;
use rustdoc_json_types::{Crate, Item, ItemKind, ItemSummary, Visibility, FORMAT_VERSION};
use std::collections::HashMap;

use crate::json_find::SelectorPart;

Expand All @@ -26,7 +26,7 @@ fn errors_on_missing_links() {
root: id("0"),
crate_version: None,
includes_private: false,
index: FxHashMap::from_iter([(
index: HashMap::from_iter([(
id("0"),
Item {
name: Some("root".to_owned()),
Expand All @@ -35,7 +35,7 @@ fn errors_on_missing_links() {
span: None,
visibility: Visibility::Public,
docs: None,
links: FxHashMap::from_iter([("Not Found".to_owned(), id("1"))]),
links: HashMap::from_iter([("Not Found".to_owned(), id("1"))]),
attrs: vec![],
deprecation: None,
inner: ItemEnum::Module(Module {
Expand All @@ -45,8 +45,8 @@ fn errors_on_missing_links() {
}),
},
)]),
paths: FxHashMap::default(),
external_crates: FxHashMap::default(),
paths: HashMap::default(),
external_crates: HashMap::default(),
format_version: rustdoc_json_types::FORMAT_VERSION,
};

Expand All @@ -72,7 +72,7 @@ fn errors_on_local_in_paths_and_not_index() {
root: id("0:0:1572"),
crate_version: None,
includes_private: false,
index: FxHashMap::from_iter([
index: HashMap::from_iter([
(
id("0:0:1572"),
Item {
Expand All @@ -82,7 +82,7 @@ fn errors_on_local_in_paths_and_not_index() {
span: None,
visibility: Visibility::Public,
docs: None,
links: FxHashMap::from_iter([(("prim@i32".to_owned(), id("0:1:1571")))]),
links: HashMap::from_iter([(("prim@i32".to_owned(), id("0:1:1571")))]),
attrs: Vec::new(),
deprecation: None,
inner: ItemEnum::Module(Module {
Expand All @@ -101,22 +101,22 @@ fn errors_on_local_in_paths_and_not_index() {
span: None,
visibility: Visibility::Public,
docs: None,
links: FxHashMap::default(),
links: HashMap::default(),
attrs: Vec::new(),
deprecation: None,
inner: ItemEnum::Primitive(Primitive { name: "i32".to_owned(), impls: vec![] }),
},
),
]),
paths: FxHashMap::from_iter([(
paths: HashMap::from_iter([(
id("0:1:1571"),
ItemSummary {
crate_id: 0,
path: vec!["microcore".to_owned(), "i32".to_owned()],
kind: ItemKind::Primitive,
},
)]),
external_crates: FxHashMap::default(),
external_crates: HashMap::default(),
format_version: rustdoc_json_types::FORMAT_VERSION,
};

Expand All @@ -136,7 +136,7 @@ fn checks_local_crate_id_is_correct() {
root: id("root"),
crate_version: None,
includes_private: false,
index: FxHashMap::from_iter([(
index: HashMap::from_iter([(
id("root"),
Item {
id: id("root"),
Expand All @@ -145,7 +145,7 @@ fn checks_local_crate_id_is_correct() {
span: None,
visibility: Visibility::Public,
docs: None,
links: FxHashMap::default(),
links: HashMap::default(),
attrs: Vec::new(),
deprecation: None,
inner: ItemEnum::Module(Module {
Expand All @@ -155,8 +155,8 @@ fn checks_local_crate_id_is_correct() {
}),
},
)]),
paths: FxHashMap::default(),
external_crates: FxHashMap::default(),
paths: HashMap::default(),
external_crates: HashMap::default(),
format_version: FORMAT_VERSION,
};
check(&krate, &[]);
Expand Down
24 changes: 24 additions & 0 deletions tests/rustdoc-gui/theme-defaults.goml
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 2 additions & 3 deletions triagebot.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -499,7 +499,6 @@ compiler-team = [
]
compiler-team-contributors = [
"@compiler-errors",
"@eholk",
"@jackh726",
"@TaKO8Ki",
"@WaffleLapkin",
Expand Down