Skip to content

Commit 089217c

Browse files
committed
don't apply clone-like deprioritization on generics
because we're not unifying the whole function at once, a function like `U -> T` would otherwise be counted as "clone-like" because the generics will just unify with anything when done seperatly.
1 parent abe0299 commit 089217c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -3559,19 +3559,22 @@ class DocSearch {
35593559

35603560
/**
35613561
* This function checks if the given list contains any
3562-
* types mentioned in the query.
3562+
* (non-generic) types mentioned in the query.
35633563
*
35643564
* @param {Array<FunctionType>} list - A list of function types.
35653565
* @param {[FunctionType]} where_clause - Trait bounds for generic items.
35663566
*/
35673567
function containsTypeFromQuery(list, where_clause) {
35683568
if (!list) return false;
35693569
for (const ty of parsedQuery.returned) {
3570+
// negative type ids are generics
3571+
if (ty < 0) continue;
35703572
if (checkIfInList(list, ty, where_clause, null, 0)) {
35713573
return true;
35723574
}
35733575
}
35743576
for (const ty of parsedQuery.elems) {
3577+
if (ty < 0) continue;
35753578
if (checkIfInList(list, ty, where_clause, null, 0)) {
35763579
return true;
35773580
}

tests/rustdoc-js-std/return-based-sort.js

+9
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@ const EXPECTED = [
1818
{ 'path': 'core::alloc::AllocError', 'name': 'clone' },
1919
],
2020
},
21+
{
22+
'query': '-> &str',
23+
'others': [
24+
// type_name_of_val should not be consider clone-like
25+
{ 'path': 'core::any', 'name': 'type_name_of_val' },
26+
// this returns `Option<&str>`, and thus should be sorted lower
27+
{ 'path': 'core::str::Split', 'name': 'next' },
28+
],
29+
},
2130
]

0 commit comments

Comments
 (0)