From ed042d05d91d0a6e385e60090682d19a684420a0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 14 Aug 2025 11:04:09 +0200 Subject: [PATCH 1/2] Correctly set up unstable items search --- src/librustdoc/html/static/js/search.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 0011544d16e2f..bb8794763182a 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1089,6 +1089,13 @@ class VlqHexDecoder { class RoaringBitmap { /** @param {string} str */ constructor(str) { + this.keys = []; + this.cardinalities = []; + this.containers = []; + + if (str === undefined || str === null) { + return; + } // https://github.com/RoaringBitmap/RoaringFormatSpec // // Roaring bitmaps are used for flags that can be kept in their @@ -1113,15 +1120,12 @@ class RoaringBitmap { } else { is_run = new Uint8Array(); } - this.keys = []; - this.cardinalities = []; for (let j = 0; j < size; ++j) { this.keys.push(u8array[i] | (u8array[i + 1] << 8)); i += 2; this.cardinalities.push((u8array[i] | (u8array[i + 1] << 8)) + 1); i += 2; } - this.containers = []; let offsets = null; if (!has_runs || this.keys.length >= 4) { offsets = []; @@ -2060,9 +2064,7 @@ class DocSearch { // Deprecated and unstable items and items with no description this.searchIndexDeprecated.set(crate, new RoaringBitmap(crateCorpus.c)); this.searchIndexEmptyDesc.set(crate, new RoaringBitmap(crateCorpus.e)); - if (crateCorpus.u !== undefined && crateCorpus.u !== null) { - this.searchIndexUnstable.set(crate, new RoaringBitmap(crateCorpus.u)); - } + this.searchIndexUnstable.set(crate, new RoaringBitmap(crateCorpus.u)); let descIndex = 0; /** From 9be17885c5765e062b7edb25c33d0799d6297c40 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 14 Aug 2025 11:04:18 +0200 Subject: [PATCH 2/2] Add regression test for unstable items --- tests/rustdoc-js/unstable.js | 13 +++++++++++++ tests/rustdoc-js/unstable.rs | 8 ++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/rustdoc-js/unstable.js create mode 100644 tests/rustdoc-js/unstable.rs diff --git a/tests/rustdoc-js/unstable.js b/tests/rustdoc-js/unstable.js new file mode 100644 index 0000000000000..305e9127678a6 --- /dev/null +++ b/tests/rustdoc-js/unstable.js @@ -0,0 +1,13 @@ +// exact-check + +// This test ensures that unstable items are sorted last. + +const EXPECTED = [ + { + 'query': 'bar', + 'others': [ + { 'path': 'unstable', 'name': 'bar2' }, + { 'path': 'unstable', 'name': 'bar1' }, + ], + }, +]; diff --git a/tests/rustdoc-js/unstable.rs b/tests/rustdoc-js/unstable.rs new file mode 100644 index 0000000000000..102b8f24edc61 --- /dev/null +++ b/tests/rustdoc-js/unstable.rs @@ -0,0 +1,8 @@ +#![feature(staged_api)] +#![stable(feature = "another", since = "1.0.0")] + +#[unstable(feature = "tadam", issue = "none")] +pub fn bar1() {} + +#[stable(feature = "another", since = "1.0.0")] +pub fn bar2() {}