Skip to content

Commit 0707281

Browse files
committed
rustdoc: account for path distance in doc aliases
1 parent 7a62743 commit 0707281

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3933,16 +3933,25 @@ class DocSearch {
39333933
* @returns {Promise<rustdoc.PlainResultObject?>}
39343934
*/
39353935
const handleAlias = async(name, alias, dist, index) => {
3936+
const item = nonnull(await this.getRow(alias, false));
3937+
// space both is an alias for ::,
3938+
// and is also allowed to appear in doc alias names
3939+
const path_dist = name.includes(" ") || parsedQuery.elems.length === 0 ?
3940+
0 : checkRowPath(parsedQuery.elems[0].pathWithoutLast, item);
3941+
// path distance exceeds max, omit alias from results
3942+
if (path_dist === null) {
3943+
return null;
3944+
}
39363945
return {
39373946
id: alias,
39383947
dist,
3939-
path_dist: 0,
3948+
path_dist,
39403949
index,
39413950
alias: name,
39423951
is_alias: true,
39433952
elems: [], // only used in type-based queries
39443953
returned: [], // only used in type-based queries
3945-
item: nonnull(await this.getRow(alias, false)),
3954+
item,
39463955
};
39473956
};
39483957
/**

tests/rustdoc-js/alias-path-distance-146214.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
// consider path distance for doc aliases
44
// regression test for <https://github.com/rust-lang/rust/issues/146214>
55

6-
const EXPECTED = {
7-
'query': 'Foo::zzz',
8-
'others': [{ 'path': 'alias_path_distance::Foo', 'name': 'baz' }],
9-
};
6+
const EXPECTED = [
7+
{
8+
'query': 'Foo::zzz',
9+
'others': [
10+
{ 'path': 'alias_path_distance::Foo', 'name': 'baz' },
11+
],
12+
},
13+
{
14+
'query': '"Foo::zzz"',
15+
'others': [
16+
{ 'path': 'alias_path_distance::Foo', 'name': 'baz' },
17+
],
18+
},
19+
];

0 commit comments

Comments
 (0)