Skip to content

Commit 10ae21d

Browse files
authored
Unrolled build for rust-lang#132569
Rollup merge of rust-lang#132569 - lolbinarycat:rustdoc-search-path-end-empty-v2, r=notriddle rustdoc search: allow queries to end in an empty path segment fixes rust-lang#129707 this can be used to show all items in a module, or all associated items for a type. currently sufferes slightly due to case insensitivity, so `Option::` will also show items in the `option::` module. it disables the checking of the last path element, otherwise only items with short names will be shown r? `@notriddle`
2 parents ee4a56e + cd46ff6 commit 10ae21d

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

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

+15-5
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,6 @@ function createQueryElement(query, parserState, name, generics, isInGenerics) {
692692
const quadcolon = /::\s*::/.exec(path);
693693
if (path.startsWith("::")) {
694694
throw ["Paths cannot start with ", "::"];
695-
} else if (path.endsWith("::")) {
696-
throw ["Paths cannot end with ", "::"];
697695
} else if (quadcolon !== null) {
698696
throw ["Unexpected ", quadcolon[0]];
699697
}
@@ -3974,18 +3972,19 @@ class DocSearch {
39743972

39753973
if (parsedQuery.foundElems === 1 && !parsedQuery.hasReturnArrow) {
39763974
const elem = parsedQuery.elems[0];
3977-
for (const id of this.nameTrie.search(elem.normalizedPathLast, this.tailTable)) {
3975+
// use arrow functions to preserve `this`.
3976+
const handleNameSearch = id => {
39783977
const row = this.searchIndex[id];
39793978
if (!typePassesFilter(elem.typeFilter, row.ty) ||
39803979
(filterCrates !== null && row.crate !== filterCrates)) {
3981-
continue;
3980+
return;
39823981
}
39833982

39843983
let pathDist = 0;
39853984
if (elem.fullPath.length > 1) {
39863985
pathDist = checkPath(elem.pathWithoutLast, row);
39873986
if (pathDist === null) {
3988-
continue;
3987+
return;
39893988
}
39903989
}
39913990

@@ -4008,9 +4007,20 @@ class DocSearch {
40084007
maxEditDistance,
40094008
);
40104009
}
4010+
};
4011+
if (elem.normalizedPathLast !== "") {
4012+
const last = elem.normalizedPathLast;
4013+
for (const id of this.nameTrie.search(last, this.tailTable)) {
4014+
handleNameSearch(id);
4015+
}
40114016
}
40124017
const length = this.searchIndex.length;
4018+
40134019
for (let i = 0, nSearchIndex = length; i < nSearchIndex; ++i) {
4020+
// queries that end in :: bypass the trie
4021+
if (elem.normalizedPathLast === "") {
4022+
handleNameSearch(i);
4023+
}
40144024
const row = this.searchIndex[i];
40154025
if (filterCrates !== null && row.crate !== filterCrates) {
40164026
continue;

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

-8
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,6 @@ const PARSED = [
143143
returned: [],
144144
error: "Unexpected `:: ::`",
145145
},
146-
{
147-
query: "a::b::",
148-
elems: [],
149-
foundElems: 0,
150-
userQuery: "a::b::",
151-
returned: [],
152-
error: "Paths cannot end with `::`",
153-
},
154146
{
155147
query: ":a",
156148
elems: [],
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const EXPECTED = {
2+
'query': 'Option::',
3+
'others': [
4+
{ 'path': 'std::option::Option', 'name': 'get_or_insert_default' },
5+
],
6+
}

0 commit comments

Comments
 (0)