Skip to content

Commit

Permalink
Rollup merge of rust-lang#108656 - GuillaumeGomez:rustdoc-search-uncl…
Browse files Browse the repository at this point in the history
…osed-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`
  • Loading branch information
matthiaskrgr authored Mar 3, 2023
2 parents cb81046 + 892d73d commit 97280be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,15 @@ function initSearch(rawSearchIndex) {
}
const posBefore = parserState.pos;
getNextElem(query, parserState, elems, endChar === ">");
if (endChar !== "") {
if (parserState.pos >= parserState.length) {
throw new Error("Unclosed `<`");
}
const c2 = parserState.userQuery[parserState.pos];
if (!isSeparatorCharacter(c2) && c2 !== endChar) {
throw new Error(`Expected \`${endChar}\`, found \`${c2}\``);
}
}
// This case can be encountered if `getNextElem` encountered a "stop character" right
// from the start. For example if you have `,,` or `<>`. In this case, we simply move up
// the current position to continue the parsing.
Expand All @@ -454,7 +463,10 @@ function initSearch(rawSearchIndex) {
}
foundStopChar = false;
}
// We are either at the end of the string or on the `endChar`` character, let's move forward
if (parserState.pos >= parserState.length && endChar !== "") {
throw new Error("Unclosed `<`");
}
// We are either at the end of the string or on the `endChar` character, let's move forward
// in any case.
parserState.pos += 1;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/rustdoc-js-std/parser-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const QUERY = [
"a!!",
"mod:a!",
"a!::a",
"a<",
];

const PARSED = [
Expand Down Expand Up @@ -402,4 +403,13 @@ const PARSED = [
userQuery: "a!::a",
error: 'Cannot have associated items in macros',
},
{
elems: [],
foundElems: 0,
original: "a<",
returned: [],
typeFilter: -1,
userQuery: "a<",
error: "Unclosed `<`",
},
];

0 comments on commit 97280be

Please sign in to comment.