Skip to content

Commit fb2c74f

Browse files
committed
in type based search, put functions first
1 parent cbc94ef commit fb2c74f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const TY_PRIMITIVE = itemTypes.indexOf("primitive");
6363
const TY_GENERIC = itemTypes.indexOf("generic");
6464
const TY_IMPORT = itemTypes.indexOf("import");
6565
const TY_TRAIT = itemTypes.indexOf("trait");
66+
const TY_FN = itemTypes.indexOf("fn");
6667
const ROOT_PATH = typeof window !== "undefined" ? window.rootPath : "../";
6768

6869
// Hard limit on how deep to recurse into generics when doing type-driven search.
@@ -2749,6 +2750,15 @@ class DocSearch {
27492750
return a - b;
27502751
}
27512752

2753+
// in type based search, put functions first
2754+
if (parsedQuery.hasReturnArrow) {
2755+
a = (aaa.item.ty !== TY_FN);
2756+
b = (bbb.item.ty !== TY_FN);
2757+
if (a !== b) {
2758+
return a - b;
2759+
}
2760+
}
2761+
27522762
// Sort by distance in the path part, if specified
27532763
// (less changes required to match means higher rankings)
27542764
a = aaa.path_dist;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const EXPECTED = {
22
'query': '-> char',
33
'others': [
4+
{ 'path': 'std::char', 'name': 'from_digit' },
45
{ 'path': 'std::char', 'name': 'MAX' },
56
],
67
}

0 commit comments

Comments
 (0)