From b39357bbf3fc4688793a6a4671b509efde8834ce Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 8 Aug 2025 14:04:47 +0200 Subject: [PATCH 1/2] Rank doc aliases lower than equivalently matched items --- src/librustdoc/html/static/js/search.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 2caf214ff73d4..505652c0f4a7c 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -3340,6 +3340,13 @@ class DocSearch { return a - b; } + // sort doc alias items later + a = Number(aaa.item.is_alias === true); + b = Number(bbb.item.is_alias === true); + if (a !== b) { + return a - b; + } + // sort by item name (lexicographically larger goes later) let aw = aaa.word; let bw = bbb.word; From a34bd2baf586b4a6284b11852fede24ad557f787 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 8 Aug 2025 14:05:19 +0200 Subject: [PATCH 2/2] Add regression test for doc alias matching vs equivalently matched items --- .../rustdoc-js/doc-alias-after-other-items.js | 38 +++++++++++++++++++ .../rustdoc-js/doc-alias-after-other-items.rs | 9 +++++ 2 files changed, 47 insertions(+) create mode 100644 tests/rustdoc-js/doc-alias-after-other-items.js create mode 100644 tests/rustdoc-js/doc-alias-after-other-items.rs diff --git a/tests/rustdoc-js/doc-alias-after-other-items.js b/tests/rustdoc-js/doc-alias-after-other-items.js new file mode 100644 index 0000000000000..5b22ef6769825 --- /dev/null +++ b/tests/rustdoc-js/doc-alias-after-other-items.js @@ -0,0 +1,38 @@ +// exact-check + +// Checking that doc aliases are always listed after items with equivalent matching. + +const EXPECTED = [ + { + 'query': 'coo', + 'others': [ + { + 'path': 'doc_alias_after_other_items', + 'name': 'Foo', + 'href': '../doc_alias_after_other_items/struct.Foo.html', + }, + { + 'path': 'doc_alias_after_other_items', + 'name': 'bar', + 'alias': 'Boo', + 'is_alias': true + }, + ], + }, + { + 'query': '"confiture"', + 'others': [ + { + 'path': 'doc_alias_after_other_items', + 'name': 'Confiture', + 'href': '../doc_alias_after_other_items/struct.Confiture.html', + }, + { + 'path': 'doc_alias_after_other_items', + 'name': 'this_is_a_long_name', + 'alias': 'Confiture', + 'is_alias': true + }, + ], + }, +]; diff --git a/tests/rustdoc-js/doc-alias-after-other-items.rs b/tests/rustdoc-js/doc-alias-after-other-items.rs new file mode 100644 index 0000000000000..2ed555c8e2f37 --- /dev/null +++ b/tests/rustdoc-js/doc-alias-after-other-items.rs @@ -0,0 +1,9 @@ +pub struct Foo; + +#[doc(alias = "Boo")] +pub fn bar() {} + +pub struct Confiture; + +#[doc(alias = "Confiture")] +pub fn this_is_a_long_name() {}