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 e350324
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 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`',
},
],
},
];
6 changes: 0 additions & 6 deletions tests/rustdoc-js/non-english-identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const PARSED = [
}],
returned: [],
foundElems: 1,
original: "中文",
userQuery: "中文",
error: null,
},
Expand All @@ -26,7 +25,6 @@ const PARSED = [
typeFilter: -1,
}],
foundElems: 1,
original: "_0Mixed中英文",
returned: [],
userQuery: "_0mixed中英文",
error: null,
Expand All @@ -42,7 +40,6 @@ const PARSED = [
typeFilter: -1,
}],
foundElems: 1,
original: "my_crate::中文API",
returned: [],
userQuery: "my_crate::中文api",
error: null,
Expand Down Expand Up @@ -71,7 +68,6 @@ const PARSED = [
foundElems: 3,
totalElems: 5,
literalSearch: true,
original: "类型A,类型B<约束C>->返回类型<关联类型=路径::约束D>",
returned: [{
name: "返回类型",
fullPath: ["返回类型"],
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 e350324

Please sign in to comment.