Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ::,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant "a space is both an alias...", but not sure

// and is also allowed to appear in doc alias names
const path_dist = name.includes(" ") ?
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,
};
};
/**
Expand Down
19 changes: 19 additions & 0 deletions tests/rustdoc-js/alias-path-distance-146214.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// exact-check

// 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' },
],
},
{
'query': '"Foo::zzz"',
'others': [
{ 'path': 'alias_path_distance::Foo', 'name': 'baz' },
],
},
];
14 changes: 14 additions & 0 deletions tests/rustdoc-js/alias-path-distance-146214.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![crate_name = "alias_path_distance"]

pub struct Foo;
pub struct Bar;

impl Foo {
#[doc(alias = "zzz")]
pub fn baz() {}
}

impl Bar {
#[doc(alias = "zzz")]
pub fn baz() {}
}
10 changes: 10 additions & 0 deletions tests/rustdoc-js/alias-rank-lower-140968.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// rank doc aliases lower than exact matches
// regression test for <https://github.com/rust-lang/rust/issues/140968>

const EXPECTED = {
'query': 'Foo',
'others': [
{ 'path': 'alias_rank_lower', 'name': 'Foo' },
{ 'path': 'alias_rank_lower', 'name': 'Bar' },
],
};
6 changes: 6 additions & 0 deletions tests/rustdoc-js/alias-rank-lower-140968.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![crate_name = "alias_rank_lower"]

pub struct Foo;

#[doc(alias = "Foo")]
pub struct Bar;
Loading