Rollup merge of #130009 - notriddle:notriddle/trailing-arrow, r=lolbinarycat,GuillaumeGomez

rustdoc-search: allow trailing `Foo ->` arg search

Fixes #129710
This commit is contained in:
Matthias Krüger 2024-09-07 23:30:14 +02:00 committed by GitHub
commit 04b4523efc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 81 additions and 14 deletions

View file

@ -41,6 +41,7 @@ let ParserState;
* foundElems: number,
* totalElems: number,
* literalSearch: boolean,
* hasReturnArrow: boolean,
* corrections: Array<{from: string, to: integer}> | null,
* typeFingerprint: Uint32Array,
* error: Array<string> | null,

View file

@ -657,7 +657,7 @@ function createQueryElement(query, parserState, name, generics, isInGenerics) {
}
const typeFilter = parserState.typeFilter;
parserState.typeFilter = null;
if (name === "!") {
if (name.trim() === "!") {
if (typeFilter !== null && typeFilter !== "primitive") {
throw [
"Invalid search type: primitive never type ",
@ -1795,6 +1795,7 @@ class DocSearch {
// Total number of elements (includes generics).
totalElems: 0,
literalSearch: false,
hasReturnArrow: false,
error: null,
correction: null,
proposeCorrectionFrom: null,
@ -1823,6 +1824,7 @@ class DocSearch {
continue;
} else if (c === "-" || c === ">") {
if (isReturnArrow(parserState)) {
query.hasReturnArrow = true;
break;
}
throw ["Unexpected ", c, " (did you mean ", "->", "?)"];
@ -1889,9 +1891,7 @@ class DocSearch {
// Get returned elements.
getItemsBefore(query, parserState, query.returned, "");
// Nothing can come afterward!
if (query.returned.length === 0) {
throw ["Expected at least one item after ", "->"];
}
query.hasReturnArrow = true;
break;
} else {
parserState.pos += 1;
@ -3249,7 +3249,7 @@ class DocSearch {
this.buildFunctionTypeFingerprint(elem, parsedQuery.typeFingerprint, fps);
}
if (parsedQuery.foundElems === 1 && parsedQuery.returned.length === 0) {
if (parsedQuery.foundElems === 1 && !parsedQuery.hasReturnArrow) {
if (parsedQuery.elems.length === 1) {
const elem = parsedQuery.elems[0];
const length = this.searchIndex.length;