Skip to content

Commit e350324

Browse files
committed
rustdoc-search: fix where clause highlight with dup generics
Essentially, the unifier only adds generics to a parameter when a part of its where clause is highlighted. To make that work, the formatter can ignore the empties.
1 parent bccb9f7 commit e350324

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,9 @@ function initSearch(rawSearchIndex) {
15721572
for (const nested of fnType.generics) {
15731573
writeFn(nested, where);
15741574
}
1575-
whereClause.set(fnParamNames[-1 - fnType.id], where);
1575+
if (where.length > 0) {
1576+
whereClause.set(fnParamNames[-1 - fnType.id], where);
1577+
}
15761578
} else {
15771579
if (fnType.ty === TY_PRIMITIVE) {
15781580
if (fnType.id === typeNameIdOfArray || fnType.id === typeNameIdOfSlice ||
@@ -2913,7 +2915,7 @@ function initSearch(rawSearchIndex) {
29132915
sorted_returned,
29142916
sorted_others,
29152917
parsedQuery);
2916-
await handleAliases(ret, parsedQuery.original.replace(/"/g, ""),
2918+
await handleAliases(ret, parsedQuery.userQuery.replace(/"/g, ""),
29172919
filterCrates, currentCrate);
29182920
await Promise.all([ret.others, ret.returned, ret.in_args].map(async list => {
29192921
const descs = await Promise.all(list.map(result => {

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

-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ const PARSED = [
195195
query: "a:b",
196196
elems: [],
197197
foundElems: 0,
198-
original: "a:b",
199198
returned: [],
200199
userQuery: "a:b",
201200
error: "Unknown type filter `a`",

tests/rustdoc-js-std/vec-type-signatures.js

+12
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,16 @@ const EXPECTED = [
1919
{ 'path': 'std::vec::IntoIter', 'name': 'next_chunk' },
2020
],
2121
},
22+
{
23+
'query': 'vec<Allocator> -> Box<[T]>',
24+
'others': [
25+
{
26+
'path': 'std::boxed::Box',
27+
'name': 'from',
28+
'displayType': '`Vec`<T, `A`> -> `Box`<`[T]`, A>',
29+
'displayMappedNames': `T = T`,
30+
'displayWhereClause': 'A: `Allocator`',
31+
},
32+
],
33+
},
2234
];

tests/rustdoc-js/non-english-identifier.js

-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const PARSED = [
1111
}],
1212
returned: [],
1313
foundElems: 1,
14-
original: "中文",
1514
userQuery: "中文",
1615
error: null,
1716
},
@@ -26,7 +25,6 @@ const PARSED = [
2625
typeFilter: -1,
2726
}],
2827
foundElems: 1,
29-
original: "_0Mixed中英文",
3028
returned: [],
3129
userQuery: "_0mixed中英文",
3230
error: null,
@@ -42,7 +40,6 @@ const PARSED = [
4240
typeFilter: -1,
4341
}],
4442
foundElems: 1,
45-
original: "my_crate::中文API",
4643
returned: [],
4744
userQuery: "my_crate::中文api",
4845
error: null,
@@ -71,7 +68,6 @@ const PARSED = [
7168
foundElems: 3,
7269
totalElems: 5,
7370
literalSearch: true,
74-
original: "类型A,类型B<约束C>->返回类型<关联类型=路径::约束D>",
7571
returned: [{
7672
name: "返回类型",
7773
fullPath: ["返回类型"],
@@ -93,7 +89,6 @@ const PARSED = [
9389
typeFilter: 16,
9490
}],
9591
foundElems: 1,
96-
original: "my_crate 中文宏!",
9792
returned: [],
9893
userQuery: "my_crate 中文宏!",
9994
error: null,
@@ -102,7 +97,6 @@ const PARSED = [
10297
query: '非法符号——',
10398
elems: [],
10499
foundElems: 0,
105-
original: "非法符号——",
106100
returned: [],
107101
userQuery: "非法符号——",
108102
error: "Unexpected `—` after `号` (not a valid identifier)",

0 commit comments

Comments
 (0)