From 18fd6eab3a14fa86fca32b3884811aa1f8d29fea Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 14 Aug 2025 13:02:40 +0200 Subject: [PATCH 1/4] Revert "Correctly handle when there are no unstable items in the documented crate" This reverts commit cd79c7189db7b611f9199fd12ba56563afa18642. --- src/librustdoc/html/static/js/search.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 0011544d16e2f..10e01b4e26274 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -2060,9 +2060,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 1975b06583cb558f82d8cc92ab5b672d9290acf3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 14 Aug 2025 13:02:56 +0200 Subject: [PATCH 2/4] Revert "rustdoc search: add performance note about searchIndexUnstable check" This reverts commit fdbc8d08a63a3d34b7aebabb2f18a768462a98c4. --- src/librustdoc/html/static/js/search.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 10e01b4e26274..516e857ee765a 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -3333,12 +3333,6 @@ class DocSearch { } // sort unstable items later - // FIXME: there is some doubt if this is the most effecient way to implement this. - // alternative options include: - // * put is_unstable on each item when the index is built. - // increases memory usage but avoids a hashmap lookup. - // * put is_unstable on each item before sorting. - // better worst case performance but worse average case performance. a = Number( // @ts-expect-error this.searchIndexUnstable.get(aaa.item.crate).contains(aaa.item.bitIndex), From 2820fcc8302d25acdefbcfd4351831441dc177c6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 14 Aug 2025 13:04:08 +0200 Subject: [PATCH 3/4] Revert "rustdoc: IndexItem::{stability -> is_unstable}" This reverts commit 5e8ebd5ecd8546591a6707ac9e1a3b8a64c72f76. --- src/librustdoc/formats/cache.rs | 2 +- src/librustdoc/html/render/mod.rs | 7 ++++++- src/librustdoc/html/render/search_index.rs | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 918b292466d31..1e674cc5e89a4 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -602,7 +602,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It search_type, aliases, deprecation, - is_unstable: item.stability(tcx).map(|x| x.is_unstable()).unwrap_or(false), + stability: item.stability(tcx), }; cache.search_index.push(index_item); } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 9525984707583..41ebaeade1d34 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -139,7 +139,12 @@ pub(crate) struct IndexItem { pub(crate) search_type: Option, pub(crate) aliases: Box<[Symbol]>, pub(crate) deprecation: Option, - pub(crate) is_unstable: bool, + pub(crate) stability: Option, +} +impl IndexItem { + fn is_unstable(&self) -> bool { + matches!(&self.stability, Some(Stability { level: StabilityLevel::Unstable { .. }, .. })) + } } /// A type used for the search index. diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index 93c9df8c04935..8d510a393df57 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -93,7 +93,7 @@ pub(crate) fn build_index( ), aliases: item.attrs.get_doc_aliases(), deprecation: item.deprecation(tcx), - is_unstable: item.stability(tcx).is_some_and(|x| x.is_unstable()), + stability: item.stability(tcx), }); } } @@ -713,7 +713,7 @@ pub(crate) fn build_index( // bitmasks always use 1-indexing for items, with 0 as the crate itself deprecated.push(u32::try_from(index + 1).unwrap()); } - if item.is_unstable { + if item.is_unstable() { unstable.push(u32::try_from(index + 1).unwrap()); } } From a195cf63b88ecfccebeae59e150a65ec5732779b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 14 Aug 2025 13:06:05 +0200 Subject: [PATCH 4/4] Revert "rustdoc search: prefer stable items in search results" This reverts commit 1140e90074b0cbcfdea8535e4b51877e2838227e. --- src/librustdoc/formats/cache.rs | 1 - src/librustdoc/html/render/mod.rs | 6 ------ src/librustdoc/html/render/search_index.rs | 6 ------ src/librustdoc/html/static/js/rustdoc.d.ts | 5 +---- src/librustdoc/html/static/js/search.js | 21 +-------------------- tests/rustdoc-js-std/core-transmute.js | 2 +- tests/rustdoc-js-std/transmute-fail.js | 2 +- tests/rustdoc-js-std/transmute.js | 2 +- tests/rustdoc-js/sort-stability.js | 9 --------- tests/rustdoc-js/sort-stability.rs | 16 ---------------- 10 files changed, 5 insertions(+), 65 deletions(-) delete mode 100644 tests/rustdoc-js/sort-stability.js delete mode 100644 tests/rustdoc-js/sort-stability.rs diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 1e674cc5e89a4..80399cf3842aa 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -602,7 +602,6 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It search_type, aliases, deprecation, - stability: item.stability(tcx), }; cache.search_index.push(index_item); } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 41ebaeade1d34..a46253237db21 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -139,12 +139,6 @@ pub(crate) struct IndexItem { pub(crate) search_type: Option, pub(crate) aliases: Box<[Symbol]>, pub(crate) deprecation: Option, - pub(crate) stability: Option, -} -impl IndexItem { - fn is_unstable(&self) -> bool { - matches!(&self.stability, Some(Stability { level: StabilityLevel::Unstable { .. }, .. })) - } } /// A type used for the search index. diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index 8d510a393df57..e2f86b8a8549e 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -93,7 +93,6 @@ pub(crate) fn build_index( ), aliases: item.attrs.get_doc_aliases(), deprecation: item.deprecation(tcx), - stability: item.stability(tcx), }); } } @@ -656,7 +655,6 @@ pub(crate) fn build_index( let mut parents_backref_queue = VecDeque::new(); let mut functions = String::with_capacity(self.items.len()); let mut deprecated = Vec::with_capacity(self.items.len()); - let mut unstable = Vec::with_capacity(self.items.len()); let mut type_backref_queue = VecDeque::new(); @@ -713,9 +711,6 @@ pub(crate) fn build_index( // bitmasks always use 1-indexing for items, with 0 as the crate itself deprecated.push(u32::try_from(index + 1).unwrap()); } - if item.is_unstable() { - unstable.push(u32::try_from(index + 1).unwrap()); - } } for (index, path) in &revert_extra_paths { @@ -754,7 +749,6 @@ pub(crate) fn build_index( crate_data.serialize_field("r", &re_exports)?; crate_data.serialize_field("b", &self.associated_item_disambiguators)?; crate_data.serialize_field("c", &bitmap_to_string(&deprecated))?; - crate_data.serialize_field("u", &bitmap_to_string(&unstable))?; crate_data.serialize_field("e", &bitmap_to_string(&self.empty_desc))?; crate_data.serialize_field("P", ¶m_names)?; if has_aliases { diff --git a/src/librustdoc/html/static/js/rustdoc.d.ts b/src/librustdoc/html/static/js/rustdoc.d.ts index b082b65ab576e..3d30a7adb9820 100644 --- a/src/librustdoc/html/static/js/rustdoc.d.ts +++ b/src/librustdoc/html/static/js/rustdoc.d.ts @@ -129,7 +129,7 @@ declare namespace rustdoc { /** * A single parsed "atom" in a search query. For example, - * + * * std::fmt::Formatter, Write -> Result<()> * ┏━━━━━━━━━━━━━━━━━━ ┌──── ┏━━━━━┅┅┅┅┄┄┄┄┄┄┄┄┄┄┄┄┄┄┐ * ┃ │ ┗ QueryElement { ┊ @@ -449,8 +449,6 @@ declare namespace rustdoc { * of `p`) but is used for modules items like free functions. * * `c` is an array of item indices that are deprecated. - * - * `u` is an array of item indices that are unstable. */ type RawSearchIndexCrate = { doc: string, @@ -465,7 +463,6 @@ declare namespace rustdoc { p: Array<[number, string] | [number, string, number] | [number, string, number, number] | [number, string, number, number, string]>, b: Array<[number, String]>, c: string, - u: string, r: Array<[number, number]>, P: Array<[number, string]>, }; diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 516e857ee765a..505652c0f4a7c 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1464,11 +1464,6 @@ class DocSearch { * @type {Map} */ this.searchIndexEmptyDesc = new Map(); - /** - * @type {Map} - */ - this.searchIndexUnstable = new Map(); - /** * @type {Uint32Array} */ @@ -2057,10 +2052,9 @@ class DocSearch { }; const descShardList = [descShard]; - // Deprecated and unstable items and items with no description + // Deprecated items and items with no description this.searchIndexDeprecated.set(crate, new RoaringBitmap(crateCorpus.c)); this.searchIndexEmptyDesc.set(crate, new RoaringBitmap(crateCorpus.e)); - this.searchIndexUnstable.set(crate, new RoaringBitmap(crateCorpus.u)); let descIndex = 0; /** @@ -3332,19 +3326,6 @@ class DocSearch { return a - b; } - // sort unstable items later - a = Number( - // @ts-expect-error - this.searchIndexUnstable.get(aaa.item.crate).contains(aaa.item.bitIndex), - ); - b = Number( - // @ts-expect-error - this.searchIndexUnstable.get(bbb.item.crate).contains(bbb.item.bitIndex), - ); - if (a !== b) { - return a - b; - } - // sort by crate (current crate comes first) a = Number(aaa.item.crate !== preferredCrate); b = Number(bbb.item.crate !== preferredCrate); diff --git a/tests/rustdoc-js-std/core-transmute.js b/tests/rustdoc-js-std/core-transmute.js index b15f398902c31..8c9910a32d7f1 100644 --- a/tests/rustdoc-js-std/core-transmute.js +++ b/tests/rustdoc-js-std/core-transmute.js @@ -3,9 +3,9 @@ const EXPECTED = [ { 'query': 'generic:T -> generic:U', 'others': [ - { 'path': 'core::mem', 'name': 'transmute' }, { 'path': 'core::intrinsics::simd', 'name': 'simd_as' }, { 'path': 'core::intrinsics::simd', 'name': 'simd_cast' }, + { 'path': 'core::mem', 'name': 'transmute' }, ], }, ]; diff --git a/tests/rustdoc-js-std/transmute-fail.js b/tests/rustdoc-js-std/transmute-fail.js index 459e8dc3f0029..ddfb276194818 100644 --- a/tests/rustdoc-js-std/transmute-fail.js +++ b/tests/rustdoc-js-std/transmute-fail.js @@ -6,9 +6,9 @@ const EXPECTED = [ // should-fail tag and the search query below: 'query': 'generic:T -> generic:T', 'others': [ - { 'path': 'std::mem', 'name': 'transmute' }, { 'path': 'std::intrinsics::simd', 'name': 'simd_as' }, { 'path': 'std::intrinsics::simd', 'name': 'simd_cast' }, + { 'path': 'std::mem', 'name': 'transmute' }, ], }, ]; diff --git a/tests/rustdoc-js-std/transmute.js b/tests/rustdoc-js-std/transmute.js index a85b02e29947e..f52e0ab14362d 100644 --- a/tests/rustdoc-js-std/transmute.js +++ b/tests/rustdoc-js-std/transmute.js @@ -5,9 +5,9 @@ const EXPECTED = [ // should-fail tag and the search query below: 'query': 'generic:T -> generic:U', 'others': [ - { 'path': 'std::mem', 'name': 'transmute' }, { 'path': 'std::intrinsics::simd', 'name': 'simd_as' }, { 'path': 'std::intrinsics::simd', 'name': 'simd_cast' }, + { 'path': 'std::mem', 'name': 'transmute' }, ], }, ]; diff --git a/tests/rustdoc-js/sort-stability.js b/tests/rustdoc-js/sort-stability.js deleted file mode 100644 index 8c095619a0866..0000000000000 --- a/tests/rustdoc-js/sort-stability.js +++ /dev/null @@ -1,9 +0,0 @@ -const EXPECTED = [ - { - 'query': 'foo', - 'others': [ - {"path": "sort_stability::old", "name": "foo"}, - {"path": "sort_stability::new", "name": "foo"}, - ], - }, -]; diff --git a/tests/rustdoc-js/sort-stability.rs b/tests/rustdoc-js/sort-stability.rs deleted file mode 100644 index 68662bb3aab6c..0000000000000 --- a/tests/rustdoc-js/sort-stability.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(staged_api)] -#![stable(feature = "foo_lib", since = "1.0.0")] - -#[stable(feature = "old_foo", since = "1.0.1")] -pub mod old { - /// Old, stable foo - #[stable(feature = "old_foo", since = "1.0.1")] - pub fn foo() {} -} - -#[unstable(feature = "new_foo", issue = "none")] -pub mod new { - /// New, unstable foo - #[unstable(feature = "new_foo", issue = "none")] - pub fn foo() {} -}