rustdoc: account for path distance in doc aliases

This commit is contained in:
binarycat 2025-10-14 15:16:11 -05:00
parent 7a6274373c
commit 07072812ca
2 changed files with 25 additions and 6 deletions

View file

@ -3933,16 +3933,25 @@ class DocSearch {
* @returns {Promise<rustdoc.PlainResultObject?>}
*/
const handleAlias = async(name, alias, dist, index) => {
const item = nonnull(await this.getRow(alias, false));
// space both is an alias for ::,
// and is also allowed to appear in doc alias names
const path_dist = name.includes(" ") || parsedQuery.elems.length === 0 ?
0 : checkRowPath(parsedQuery.elems[0].pathWithoutLast, item);
// path distance exceeds max, omit alias from results
if (path_dist === null) {
return null;
}
return {
id: alias,
dist,
path_dist: 0,
path_dist,
index,
alias: name,
is_alias: true,
elems: [], // only used in type-based queries
returned: [], // only used in type-based queries
item: nonnull(await this.getRow(alias, false)),
item,
};
};
/**

View file

@ -3,7 +3,17 @@
// consider path distance for doc aliases
// regression test for <https://github.com/rust-lang/rust/issues/146214>
const EXPECTED = {
'query': 'Foo::zzz',
'others': [{ 'path': 'alias_path_distance::Foo', 'name': 'baz' }],
};
const EXPECTED = [
{
'query': 'Foo::zzz',
'others': [
{ 'path': 'alias_path_distance::Foo', 'name': 'baz' },
],
},
{
'query': '"Foo::zzz"',
'others': [
{ 'path': 'alias_path_distance::Foo', 'name': 'baz' },
],
},
];