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

Rustdoc search: Emit an error for unclosed generic #108656

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -469,6 +469,15 @@ function initSearch(rawSearchIndex) {
}
const posBefore = parserState.pos;
getNextElem(query, parserState, elems, endChar === ">");
if (endChar !== "") {
if (parserState.pos >= parserState.length) {
throw ["Unclosed ", "<"];
}
const c2 = parserState.userQuery[parserState.pos];
if (!isSeparatorCharacter(c2) && c2 !== endChar) {
throw ["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 @@ -477,7 +486,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 ["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 `<`",
},
];