Skip to content

Commit

Permalink
rustdoc-search: fix where clause highlight with dup generics
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
notriddle committed Jun 8, 2024
1 parent bccb9f7 commit f817d33
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,9 @@ function initSearch(rawSearchIndex) {
for (const nested of fnType.generics) {
writeFn(nested, where);
}
whereClause.set(fnParamNames[-1 - fnType.id], where);
if (where.length > 0) {
whereClause.set(fnParamNames[-1 - fnType.id], where);
}
} else {
if (fnType.ty === TY_PRIMITIVE) {
if (fnType.id === typeNameIdOfArray || fnType.id === typeNameIdOfSlice ||
Expand Down Expand Up @@ -2913,7 +2915,7 @@ function initSearch(rawSearchIndex) {
sorted_returned,
sorted_others,
parsedQuery);
await handleAliases(ret, parsedQuery.original.replace(/"/g, ""),
await handleAliases(ret, parsedQuery.userQuery.replace(/"/g, ""),
filterCrates, currentCrate);
await Promise.all([ret.others, ret.returned, ret.in_args].map(async list => {
const descs = await Promise.all(list.map(result => {
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-js-std/parser-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ const PARSED = [
query: "a:b",
elems: [],
foundElems: 0,
original: "a:b",
returned: [],
userQuery: "a:b",
error: "Unknown type filter `a`",
Expand Down
12 changes: 12 additions & 0 deletions tests/rustdoc-js-std/vec-type-signatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@ const EXPECTED = [
{ 'path': 'std::vec::IntoIter', 'name': 'next_chunk' },
],
},
{
'query': 'vec<Allocator> -> Box<[T]>',
'others': [
{
'path': 'std::boxed::Box',
'name': 'from',
'displayType': '`Vec`<T, `A`> -> `Box`<`[T]`, A>',
'displayMappedNames': `T = T`,
'displayWhereClause': 'A: `Allocator`',
},
],
},
];
22 changes: 8 additions & 14 deletions tests/rustdoc-js/non-english-identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,54 @@ const PARSED = [
}],
returned: [],
foundElems: 1,
original: "中文",
userQuery: "中文",
error: null,
},
{
query: '_0Mixed中英文',
elems: [{
name: "_0mixed中英文",
name: "_0Mixed中英文",
fullPath: ["_0mixed中英文"],
pathWithoutLast: [],
pathLast: "_0mixed中英文",
generics: [],
typeFilter: -1,
}],
foundElems: 1,
original: "_0Mixed中英文",
returned: [],
userQuery: "_0mixed中英文",
userQuery: "_0Mixed中英文",
error: null,
},
{
query: 'my_crate::中文API',
elems: [{
name: "my_crate::中文api",
name: "my_crate::中文API",
fullPath: ["my_crate", "中文api"],
pathWithoutLast: ["my_crate"],
pathLast: "中文api",
generics: [],
typeFilter: -1,
}],
foundElems: 1,
original: "my_crate::中文API",
returned: [],
userQuery: "my_crate::中文api",
userQuery: "my_crate::中文APIi",
error: null,
},
{
query: '类型A,类型B<约束C>->返回类型<关联类型=路径::约束D>',
elems: [{
name: "类型a",
name: "类型A",
fullPath: ["类型a"],
pathWithoutLast: [],
pathLast: "类型a",
generics: [],
}, {
name: "类型b",
name: "类型B",
fullPath: ["类型b"],
pathWithoutLast: [],
pathLast: "类型b",
generics: [{
name: "约束c",
name: "约束C",
fullPath: ["约束c"],
pathWithoutLast: [],
pathLast: "约束c",
Expand All @@ -71,15 +68,14 @@ const PARSED = [
foundElems: 3,
totalElems: 5,
literalSearch: true,
original: "类型A,类型B<约束C>->返回类型<关联类型=路径::约束D>",
returned: [{
name: "返回类型",
fullPath: ["返回类型"],
pathWithoutLast: [],
pathLast: "返回类型",
generics: [],
}],
userQuery: "类型a,类型b<约束c>->返回类型<关联类型=路径::约束d>",
userQuery: "类型A,类型B<约束C>->返回类型<关联类型=路径::约束D>",
error: null,
},
{
Expand All @@ -93,7 +89,6 @@ const PARSED = [
typeFilter: 16,
}],
foundElems: 1,
original: "my_crate 中文宏!",
returned: [],
userQuery: "my_crate 中文宏!",
error: null,
Expand All @@ -102,7 +97,6 @@ const PARSED = [
query: '非法符号——',
elems: [],
foundElems: 0,
original: "非法符号——",
returned: [],
userQuery: "非法符号——",
error: "Unexpected `—` after `号` (not a valid identifier)",
Expand Down

0 comments on commit f817d33

Please sign in to comment.