Skip to content

Commit

Permalink
Rollup merge of #130009 - notriddle:notriddle/trailing-arrow, r=lolbi…
Browse files Browse the repository at this point in the history
…narycat,GuillaumeGomez

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

Fixes #129710
  • Loading branch information
GuillaumeGomez authored Sep 6, 2024
2 parents a38f6d8 + 3699e93 commit 0ed26b5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/librustdoc/html/static/js/externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ",
Expand Down Expand Up @@ -1795,6 +1795,7 @@ class DocSearch {
// Total number of elements (includes generics).
totalElems: 0,
literalSearch: false,
hasReturnArrow: false,
error: null,
correction: null,
proposeCorrectionFrom: null,
Expand Down Expand Up @@ -1823,6 +1824,7 @@ class DocSearch {
continue;
} else if (c === "-" || c === ">") {
if (isReturnArrow(parserState)) {
query.hasReturnArrow = true;
break;
}
throw ["Unexpected ", c, " (did you mean ", "->", "?)"];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions tests/rustdoc-js-std/parser-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,6 @@ const PARSED = [
userQuery: "ab'",
error: "Unexpected `'` after `b` (not a valid identifier)",
},
{
query: "a->",
elems: [],
foundElems: 0,
original: "a->",
returned: [],
userQuery: "a->",
error: "Expected at least one item after `->`",
},
{
query: '"p" <a>',
elems: [],
Expand Down
68 changes: 68 additions & 0 deletions tests/rustdoc-js-std/parser-returned.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,72 @@ const PARSED = [
userQuery: "-> !",
error: null,
},
{
query: "a->",
elems: [{
name: "a",
fullPath: ["a"],
pathWithoutLast: [],
pathLast: "a",
generics: [],
typeFilter: -1,
}],
foundElems: 1,
original: "a->",
returned: [],
userQuery: "a->",
hasReturnArrow: true,
error: null,
},
{
query: "!->",
elems: [{
name: "never",
fullPath: ["never"],
pathWithoutLast: [],
pathLast: "never",
generics: [],
typeFilter: 1,
}],
foundElems: 1,
original: "!->",
returned: [],
userQuery: "!->",
hasReturnArrow: true,
error: null,
},
{
query: "! ->",
elems: [{
name: "never",
fullPath: ["never"],
pathWithoutLast: [],
pathLast: "never",
generics: [],
typeFilter: 1,
}],
foundElems: 1,
original: "! ->",
returned: [],
userQuery: "! ->",
hasReturnArrow: true,
error: null,
},
{
query: "primitive:!->",
elems: [{
name: "never",
fullPath: ["never"],
pathWithoutLast: [],
pathLast: "never",
generics: [],
typeFilter: 1,
}],
foundElems: 1,
original: "primitive:!->",
returned: [],
userQuery: "primitive:!->",
hasReturnArrow: true,
error: null,
},
];
7 changes: 7 additions & 0 deletions tests/rustdoc-js/never-search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// exact-check

const EXPECTED = [
{
'query': '! ->',
'others': [
{ 'path': 'never_search', 'name': 'impossible' },
{ 'path': 'never_search', 'name': 'box_impossible' },
],
},
{
'query': '-> !',
'others': [
Expand Down

0 comments on commit 0ed26b5

Please sign in to comment.