From 376e0c0ba48201b1052ecd67acc26656d8fccdb5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 13 May 2026 00:33:54 +0200 Subject: [PATCH] Improve `search.js` code readability and add missing test case --- src/librustdoc/html/static/js/search.js | 6 +++++- tests/rustdoc-js/macro-kinds.js | 14 ++++++++++++++ tests/rustdoc-js/macro-kinds.rs | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 9e259e1b57a3..117437f9b20b 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -120,6 +120,8 @@ const itemTypes = Object.freeze({ traitalias: 25, generic: 26, attribute: 27, + decl_macro_attribute: 28, + decl_macro_derive: 29, }); const itemTypesName = Array.from(Object.keys(itemTypes)); @@ -1660,7 +1662,7 @@ class DocSearch { associatedItemDisambiguatorOrExternCrateUrl: raw.length === 8 ? null : raw[8], forceMacroHref: false, }; - if (item.ty === 28 || item.ty === 29) { + if (item.ty === itemTypes.decl_macro_attribute || item.ty === itemTypes.decl_macro_derive) { // "proc attribute" is 23, "proc derive" is 24 whereas "decl macro attribute" is 28 and // "decl macro derive" is 29, so 5 of difference to go from the latter to the former. item.ty -= 5; @@ -4823,6 +4825,8 @@ const longItemTypes = [ "trait alias", "", "attribute", + "", // decl macro attribute, never used as is + "", // decl macro derive, never used as is ]; // @ts-expect-error let currentResults; diff --git a/tests/rustdoc-js/macro-kinds.js b/tests/rustdoc-js/macro-kinds.js index b22b0498b1e6..b76242852431 100644 --- a/tests/rustdoc-js/macro-kinds.js +++ b/tests/rustdoc-js/macro-kinds.js @@ -28,6 +28,18 @@ const EXPECTED = [ 'href': '../macro_kinds/attr.macro2.html', 'ty': 23, }, + { + 'path': 'macro_kinds', + 'name': 'macro5', + 'href': '../macro_kinds/macro.macro5.html', + 'ty': 23, + }, + { + 'path': 'macro_kinds', + 'name': 'macro5', + 'href': '../macro_kinds/macro.macro5.html', + 'ty': 24, + }, { 'path': 'macro_kinds', 'name': 'macro4', @@ -47,12 +59,14 @@ const EXPECTED = [ 'others': [ { 'path': 'macro_kinds', 'name': 'macro1', 'href': '../macro_kinds/macro.macro1.html' }, { 'path': 'macro_kinds', 'name': 'macro2', 'href': '../macro_kinds/attr.macro2.html' }, + { 'path': 'macro_kinds', 'name': 'macro5', 'href': '../macro_kinds/macro.macro5.html' }, ], }, { 'query': 'derive:macro', 'others': [ { 'path': 'macro_kinds', 'name': 'macro1', 'href': '../macro_kinds/macro.macro1.html' }, + { 'path': 'macro_kinds', 'name': 'macro5', 'href': '../macro_kinds/macro.macro5.html' }, { 'path': 'macro_kinds', 'name': 'macro4', 'href': '../macro_kinds/derive.macro4.html' }, diff --git a/tests/rustdoc-js/macro-kinds.rs b/tests/rustdoc-js/macro-kinds.rs index 3bd753cadc67..dd0fc1c110a0 100644 --- a/tests/rustdoc-js/macro-kinds.rs +++ b/tests/rustdoc-js/macro-kinds.rs @@ -26,3 +26,9 @@ macro_rules! macro3 { macro_rules! macro4 { derive() () => {}; } + +#[macro_export] +macro_rules! macro5 { + attr() () => {}; + derive() () => {}; +}