Skip to content

Commit 5c134f6

Browse files
authored
Rollup merge of rust-lang#60134 - GuillaumeGomez:fix-index-page, r=Manishearth
Fix index-page generation Fixes rust-lang#60096. The minifier was minifying crates name in `searchIndex` key position, which was a bit problematic for multiple reasons. r? @rust-lang/rustdoc
2 parents 62bd308 + 6aa5a5d commit 5c134f6

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

Cargo.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
15231523

15241524
[[package]]
15251525
name = "minifier"
1526-
version = "0.0.29"
1526+
version = "0.0.30"
15271527
source = "registry+https://github.com/rust-lang/crates.io-index"
15281528
dependencies = [
15291529
"macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3038,7 +3038,7 @@ dependencies = [
30383038
name = "rustdoc"
30393039
version = "0.0.0"
30403040
dependencies = [
3041-
"minifier 0.0.29 (registry+https://github.com/rust-lang/crates.io-index)",
3041+
"minifier 0.0.30 (registry+https://github.com/rust-lang/crates.io-index)",
30423042
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
30433043
"pulldown-cmark 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
30443044
"tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4170,7 +4170,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
41704170
"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
41714171
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
41724172
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
4173-
"checksum minifier 0.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4950cb2617b1933e2da0446e864dfe0d6a22c22ff72297996c46e6a63b210b"
4173+
"checksum minifier 0.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "4c909e78edf61f3aa0dd2086da168cdf304329044bbf248768ca3d20253ec8c0"
41744174
"checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649"
41754175
"checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c"
41764176
"checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e"

src/librustdoc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ path = "lib.rs"
1010

1111
[dependencies]
1212
pulldown-cmark = { version = "0.4.1", default-features = false }
13-
minifier = "0.0.29"
13+
minifier = "0.0.30"
1414
tempfile = "3"
1515
parking_lot = "0.7"

src/librustdoc/html/render.rs

+11-26
Original file line numberDiff line numberDiff line change
@@ -951,40 +951,15 @@ themePicker.onblur = handleThemeButtonsBlur;
951951
key: &str,
952952
for_search_index: bool,
953953
) -> io::Result<(Vec<String>, Vec<String>, Vec<String>)> {
954-
use minifier::js;
955-
956954
let mut ret = Vec::new();
957955
let mut krates = Vec::new();
958956
let mut variables = Vec::new();
959957

960-
let mut krate = krate.to_owned();
961-
962958
if path.exists() {
963959
for line in BufReader::new(File::open(path)?).lines() {
964960
let line = line?;
965961
if for_search_index && line.starts_with("var R") {
966962
variables.push(line.clone());
967-
// We need to check if the crate name has been put into a variable as well.
968-
let tokens: js::Tokens<'_> = js::simple_minify(&line)
969-
.into_iter()
970-
.filter(js::clean_token)
971-
.collect::<Vec<_>>()
972-
.into();
973-
let mut pos = 0;
974-
while pos < tokens.len() {
975-
if let Some((var_pos, Some(value_pos))) =
976-
js::get_variable_name_and_value_positions(&tokens, pos) {
977-
if let Some(s) = tokens.0[value_pos].get_string() {
978-
if &s[1..s.len() - 1] == krate {
979-
if let Some(var) = tokens[var_pos].get_other() {
980-
krate = var.to_owned();
981-
break
982-
}
983-
}
984-
}
985-
}
986-
pos += 1;
987-
}
988963
continue;
989964
}
990965
if !line.starts_with(key) {
@@ -1340,10 +1315,20 @@ fn write_minify_replacer<W: Write>(
13401315
.into();
13411316
tokens.apply(|f| {
13421317
// We add a backline after the newly created variables.
1343-
minifier::js::aggregate_strings_into_array_with_separation(
1318+
minifier::js::aggregate_strings_into_array_with_separation_filter(
13441319
f,
13451320
"R",
13461321
Token::Char(ReservedChar::Backline),
1322+
// This closure prevents crates' names from being aggregated.
1323+
//
1324+
// The point here is to check if the string is preceded by '[' and
1325+
// "searchIndex". If so, it means this is a crate name and that it
1326+
// shouldn't be aggregated.
1327+
|tokens, pos| {
1328+
pos < 2 ||
1329+
!tokens[pos - 1].is_char(ReservedChar::OpenBracket) ||
1330+
tokens[pos - 2].get_other() != Some("searchIndex")
1331+
}
13471332
)
13481333
})
13491334
.to_string()

src/test/rustdoc/index-page.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
// aux-build:all-item-types.rs
2+
// build-aux-docs
13
// compile-flags: -Z unstable-options --enable-index-page
24

35
#![crate_name = "foo"]
46

57
// @has foo/../index.html
68
// @has - '//span[@class="in-band"]' 'List of all crates'
79
// @has - '//ul[@class="mod"]//a[@href="foo/index.html"]' 'foo'
10+
// @has - '//ul[@class="mod"]//a[@href="all_item_types/index.html"]' 'all_item_types'
811
pub struct Foo;

0 commit comments

Comments
 (0)