Skip to content

Commit 4bf0530

Browse files
authored
Unrolled build for rust-lang#118452
Rollup merge of rust-lang#118452 - notriddle:coloncolonspace, r=GuillaumeGomez,jsha rustdoc-search: allow spaces around `::` in path query This restriction made sense back when spaces separated function parameters, but now that they separate path components, there's no real ambiguity any more. Additionally, the Rust language allows it. The other two commits are misc code cleanup.
2 parents c52b876 + 930cba8 commit 4bf0530

File tree

5 files changed

+99
-51
lines changed

5 files changed

+99
-51
lines changed

src/librustdoc/html/static/js/search.js

+11-20
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,6 @@ function initSearch(rawSearchIndex) {
287287
}
288288
}
289289

290-
function isWhitespace(c) {
291-
return " \t\n\r".indexOf(c) !== -1;
292-
}
293-
294290
function isSpecialStartCharacter(c) {
295291
return "<\"".indexOf(c) !== -1;
296292
}
@@ -408,7 +404,7 @@ function initSearch(rawSearchIndex) {
408404
* @return {boolean}
409405
*/
410406
function isPathSeparator(c) {
411-
return c === ":" || isWhitespace(c);
407+
return c === ":" || c === " ";
412408
}
413409

414410
/**
@@ -425,7 +421,7 @@ function initSearch(rawSearchIndex) {
425421
const c = parserState.userQuery[pos - 1];
426422
if (c === lookingFor) {
427423
return true;
428-
} else if (!isWhitespace(c)) {
424+
} else if (c !== " ") {
429425
break;
430426
}
431427
pos -= 1;
@@ -454,7 +450,7 @@ function initSearch(rawSearchIndex) {
454450
function skipWhitespace(parserState) {
455451
while (parserState.pos < parserState.userQuery.length) {
456452
const c = parserState.userQuery[parserState.pos];
457-
if (!isWhitespace(c)) {
453+
if (c !== " ") {
458454
break;
459455
}
460456
parserState.pos += 1;
@@ -473,8 +469,6 @@ function initSearch(rawSearchIndex) {
473469
const path = name.trim();
474470
if (path.length === 0 && generics.length === 0) {
475471
throw ["Unexpected ", parserState.userQuery[parserState.pos]];
476-
} else if (path === "*") {
477-
throw ["Unexpected ", "*"];
478472
}
479473
if (query.literalSearch && parserState.totalElems - parserState.genericsElems > 0) {
480474
throw ["Cannot have more than one element if you use quotes"];
@@ -512,18 +506,15 @@ function initSearch(rawSearchIndex) {
512506
bindingName,
513507
};
514508
}
509+
const quadcolon = /::\s*::/.exec(path);
515510
if (path.startsWith("::")) {
516511
throw ["Paths cannot start with ", "::"];
517512
} else if (path.endsWith("::")) {
518513
throw ["Paths cannot end with ", "::"];
519-
} else if (path.includes("::::")) {
520-
throw ["Unexpected ", "::::"];
521-
} else if (path.includes(" ::")) {
522-
throw ["Unexpected ", " ::"];
523-
} else if (path.includes(":: ")) {
524-
throw ["Unexpected ", ":: "];
525-
}
526-
const pathSegments = path.split(/::|\s+/);
514+
} else if (quadcolon !== null) {
515+
throw ["Unexpected ", quadcolon[0]];
516+
}
517+
const pathSegments = path.split(/(?:::\s*)|(?:\s+(?:::\s*)?)/);
527518
// In case we only have something like `<p>`, there is no name.
528519
if (pathSegments.length === 0 || (pathSegments.length === 1 && pathSegments[0] === "")) {
529520
if (generics.length > 0 || prevIs(parserState, ">")) {
@@ -604,7 +595,7 @@ function initSearch(rawSearchIndex) {
604595
} else {
605596
while (parserState.pos + 1 < parserState.length) {
606597
const next_c = parserState.userQuery[parserState.pos + 1];
607-
if (!isWhitespace(next_c)) {
598+
if (next_c !== " ") {
608599
break;
609600
}
610601
parserState.pos += 1;
@@ -958,7 +949,7 @@ function initSearch(rawSearchIndex) {
958949
query.literalSearch = false;
959950
foundStopChar = true;
960951
continue;
961-
} else if (isWhitespace(c)) {
952+
} else if (c === " ") {
962953
skipWhitespace(parserState);
963954
continue;
964955
}
@@ -1118,7 +1109,7 @@ function initSearch(rawSearchIndex) {
11181109
}
11191110
}
11201111
}
1121-
userQuery = userQuery.trim();
1112+
userQuery = userQuery.trim().replace(/\r|\n|\t/g, " ");
11221113
const parserState = {
11231114
length: userQuery.length,
11241115
pos: 0,

tests/rustdoc-js-std/parser-errors.js

+27-18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ const PARSED = [
1717
userQuery: "-> <p>",
1818
error: "Found generics without a path",
1919
},
20+
{
21+
query: '-> *',
22+
elems: [],
23+
foundElems: 0,
24+
original: "-> *",
25+
returned: [],
26+
userQuery: "-> *",
27+
error: "Unexpected `*`",
28+
},
2029
{
2130
query: 'a<"P">',
2231
elems: [],
@@ -143,6 +152,24 @@ const PARSED = [
143152
userQuery: "a::::b",
144153
error: "Unexpected `::::`",
145154
},
155+
{
156+
query: "a:: ::b",
157+
elems: [],
158+
foundElems: 0,
159+
original: "a:: ::b",
160+
returned: [],
161+
userQuery: "a:: ::b",
162+
error: "Unexpected `:: ::`",
163+
},
164+
{
165+
query: "a::\t::b",
166+
elems: [],
167+
foundElems: 0,
168+
original: "a:: ::b",
169+
returned: [],
170+
userQuery: "a:: ::b",
171+
error: "Unexpected `:: ::`",
172+
},
146173
{
147174
query: "a::b::",
148175
elems: [],
@@ -314,24 +341,6 @@ const PARSED = [
314341
userQuery: 'a<->',
315342
error: 'Unexpected `-` after `<`',
316343
},
317-
{
318-
query: "a:: a",
319-
elems: [],
320-
foundElems: 0,
321-
original: 'a:: a',
322-
returned: [],
323-
userQuery: 'a:: a',
324-
error: 'Unexpected `:: `',
325-
},
326-
{
327-
query: "a ::a",
328-
elems: [],
329-
foundElems: 0,
330-
original: 'a ::a',
331-
returned: [],
332-
userQuery: 'a ::a',
333-
error: 'Unexpected ` ::`',
334-
},
335344
{
336345
query: "a<a>:",
337346
elems: [],

tests/rustdoc-js-std/parser-paths.js

+48
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,54 @@ const PARSED = [
1515
userQuery: "a::b",
1616
error: null,
1717
},
18+
{
19+
query: "a:: a",
20+
elems: [{
21+
name: "a:: a",
22+
fullPath: ["a", "a"],
23+
pathWithoutLast: ["a"],
24+
pathLast: "a",
25+
generics: [],
26+
typeFilter: -1,
27+
}],
28+
foundElems: 1,
29+
original: 'a:: a',
30+
returned: [],
31+
userQuery: 'a:: a',
32+
error: null,
33+
},
34+
{
35+
query: "a ::a",
36+
elems: [{
37+
name: "a ::a",
38+
fullPath: ["a", "a"],
39+
pathWithoutLast: ["a"],
40+
pathLast: "a",
41+
generics: [],
42+
typeFilter: -1,
43+
}],
44+
foundElems: 1,
45+
original: 'a ::a',
46+
returned: [],
47+
userQuery: 'a ::a',
48+
error: null,
49+
},
50+
{
51+
query: "a :: a",
52+
elems: [{
53+
name: "a :: a",
54+
fullPath: ["a", "a"],
55+
pathWithoutLast: ["a"],
56+
pathLast: "a",
57+
generics: [],
58+
typeFilter: -1,
59+
}],
60+
foundElems: 1,
61+
original: 'a :: a',
62+
returned: [],
63+
userQuery: 'a :: a',
64+
error: null,
65+
},
1866
{
1967
query: 'A::B,C',
2068
elems: [

tests/rustdoc-js-std/parser-separators.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const PARSED = [
55
query: 'aaaaaa b',
66
elems: [
77
{
8-
name: 'aaaaaa\tb',
8+
name: 'aaaaaa b',
99
fullPath: ['aaaaaa', 'b'],
1010
pathWithoutLast: ['aaaaaa'],
1111
pathLast: 'b',
@@ -14,9 +14,9 @@ const PARSED = [
1414
},
1515
],
1616
foundElems: 1,
17-
original: "aaaaaa b",
17+
original: "aaaaaa b",
1818
returned: [],
19-
userQuery: "aaaaaa b",
19+
userQuery: "aaaaaa b",
2020
error: null,
2121
},
2222
{
@@ -40,9 +40,9 @@ const PARSED = [
4040
},
4141
],
4242
foundElems: 2,
43-
original: "aaaaaa, b",
43+
original: "aaaaaa, b",
4444
returned: [],
45-
userQuery: "aaaaaa, b",
45+
userQuery: "aaaaaa, b",
4646
error: null,
4747
},
4848
{
@@ -93,7 +93,7 @@ const PARSED = [
9393
query: 'a\tb',
9494
elems: [
9595
{
96-
name: 'a\tb',
96+
name: 'a b',
9797
fullPath: ['a', 'b'],
9898
pathWithoutLast: ['a'],
9999
pathLast: 'b',
@@ -102,9 +102,9 @@ const PARSED = [
102102
},
103103
],
104104
foundElems: 1,
105-
original: "a\tb",
105+
original: "a b",
106106
returned: [],
107-
userQuery: "a\tb",
107+
userQuery: "a b",
108108
error: null,
109109
},
110110
{
@@ -176,7 +176,7 @@ const PARSED = [
176176
pathLast: 'a',
177177
generics: [
178178
{
179-
name: 'b\tc',
179+
name: 'b c',
180180
fullPath: ['b', 'c'],
181181
pathWithoutLast: ['b'],
182182
pathLast: 'c',
@@ -187,9 +187,9 @@ const PARSED = [
187187
},
188188
],
189189
foundElems: 1,
190-
original: "a<b\tc>",
190+
original: "a<b c>",
191191
returned: [],
192-
userQuery: "a<b\tc>",
192+
userQuery: "a<b c>",
193193
error: null,
194194
},
195195
];

tests/rustdoc-js-std/parser-weird-queries.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ const PARSED = [
9292
query: 'mod\t:',
9393
elems: [],
9494
foundElems: 0,
95-
original: 'mod\t:',
95+
original: 'mod :',
9696
returned: [],
97-
userQuery: 'mod\t:',
97+
userQuery: 'mod :',
9898
error: "Unexpected `:` (expected path after type filter `mod:`)",
9999
},
100100
];

0 commit comments

Comments
 (0)