diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-09 13:58:42 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-09 13:58:42 +1000 |
| commit | 48f5929604d04484f6e6d2f047e81ee5df127633 (patch) | |
| tree | 78d4ca95da692c211090fc0621d11f9b283ae0db /src/librustdoc/html/render | |
| parent | 4c7749e8c8e50ad146da599eea3a250160c1bc2b (diff) | |
| parent | fdbc8d08a63a3d34b7aebabb2f18a768462a98c4 (diff) | |
| download | rust-48f5929604d04484f6e6d2f047e81ee5df127633.tar.gz rust-48f5929604d04484f6e6d2f047e81ee5df127633.zip | |
Rollup merge of #141658 - lolbinarycat:rustdoc-search-stability-rank-138067, r=GuillaumeGomez
rustdoc search: prefer stable items in search results fixes https://github.com/rust-lang/rust/issues/138067 this does add a new field to the search index, but since we're only listing unstable items instead of adding a boolean flag to every item, it should only increase the search index size of sysroot crates, since those are the only ones using the `staged_api` feature, at least as far as the rust project is concerned.
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 1 | ||||
| -rw-r--r-- | src/librustdoc/html/render/search_index.rs | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index a46253237db..95259847075 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -139,6 +139,7 @@ pub(crate) struct IndexItem { pub(crate) search_type: Option<IndexItemFunctionType>, pub(crate) aliases: Box<[Symbol]>, pub(crate) deprecation: Option<Deprecation>, + pub(crate) is_unstable: bool, } /// 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 e2f86b8a854..93c9df8c049 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -93,6 +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()), }); } } @@ -655,6 +656,7 @@ 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(); @@ -711,6 +713,9 @@ 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 { @@ -749,6 +754,7 @@ 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 { |
