diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-09 13:58:52 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-09 13:58:52 +1000 |
| commit | cd1e82ac7297821da7543b958fc2a440f4ac051f (patch) | |
| tree | 894ac9e8e178d3000c7f7db01cc59ba1ecc9c0ba | |
| parent | e68d62132145b86304af6315cab2ae7cf7e9a888 (diff) | |
| parent | a34bd2baf586b4a6284b11852fede24ad557f787 (diff) | |
| download | rust-cd1e82ac7297821da7543b958fc2a440f4ac051f.tar.gz rust-cd1e82ac7297821da7543b958fc2a440f4ac051f.zip | |
Rollup merge of #145100 - GuillaumeGomez:rank-doc-alias-lower, r=lolbinarycat
Rank doc aliases lower than equivalently matched items Follow-up of https://github.com/rust-lang/rust/pull/143988. cc `@lolbinarycat`
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 7 | ||||
| -rw-r--r-- | tests/rustdoc-js/doc-alias-after-other-items.js | 38 | ||||
| -rw-r--r-- | tests/rustdoc-js/doc-alias-after-other-items.rs | 9 |
3 files changed, 54 insertions, 0 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 9e422040db0..10e01b4e262 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -3365,6 +3365,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; 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 00000000000..5b22ef67698 --- /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 00000000000..2ed555c8e2f --- /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() {} |
