Skip to content

Commit 2fc4935

Browse files
authored
Rollup merge of rust-lang#108656 - GuillaumeGomez:rustdoc-search-unclosed-generic, r=notriddle
Rustdoc search: Emit an error for unclosed generic Now, search like `a<` will error as it should (and as written in the eBNF). r? `@notriddle`
2 parents 832dab3 + 8236715 commit 2fc4935

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,15 @@ function initSearch(rawSearchIndex) {
469469
}
470470
const posBefore = parserState.pos;
471471
getNextElem(query, parserState, elems, endChar === ">");
472+
if (endChar !== "") {
473+
if (parserState.pos >= parserState.length) {
474+
throw ["Unclosed ", "<"];
475+
}
476+
const c2 = parserState.userQuery[parserState.pos];
477+
if (!isSeparatorCharacter(c2) && c2 !== endChar) {
478+
throw ["Expected ", endChar, ", found ", c2];
479+
}
480+
}
472481
// This case can be encountered if `getNextElem` encountered a "stop character" right
473482
// from the start. For example if you have `,,` or `<>`. In this case, we simply move up
474483
// the current position to continue the parsing.
@@ -477,7 +486,10 @@ function initSearch(rawSearchIndex) {
477486
}
478487
foundStopChar = false;
479488
}
480-
// We are either at the end of the string or on the `endChar`` character, let's move forward
489+
if (parserState.pos >= parserState.length && endChar !== "") {
490+
throw ["Unclosed ", "<"];
491+
}
492+
// We are either at the end of the string or on the `endChar` character, let's move forward
481493
// in any case.
482494
parserState.pos += 1;
483495
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const QUERY = [
3939
"a!!",
4040
"mod:a!",
4141
"a!::a",
42+
"a<",
4243
];
4344

4445
const PARSED = [
@@ -402,4 +403,13 @@ const PARSED = [
402403
userQuery: "a!::a",
403404
error: 'Cannot have associated items in macros',
404405
},
406+
{
407+
elems: [],
408+
foundElems: 0,
409+
original: "a<",
410+
returned: [],
411+
typeFilter: -1,
412+
userQuery: "a<",
413+
error: "Unclosed `<`",
414+
},
405415
];

0 commit comments

Comments
 (0)