diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-03-11 12:55:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-11 12:55:41 +0100 |
| commit | 8596751f3b8f8824db2c9d3e136b1dc38b9a2fad (patch) | |
| tree | e79881ea19f58bf268e5e1a8eecf7ff1342928f7 /src/librustdoc/html/render | |
| parent | 790d9f349b061c8b7d113a3752b7e05c3304bccb (diff) | |
| parent | d2e4b59e60aae6f47baae337a3a7f9f04c728592 (diff) | |
| download | rust-8596751f3b8f8824db2c9d3e136b1dc38b9a2fad.tar.gz rust-8596751f3b8f8824db2c9d3e136b1dc38b9a2fad.zip | |
Rollup merge of #107629 - pitaj:rustdoc-search-deprecated, r=jsha
rustdoc: sort deprecated items lower in search closes #98759 ### Screenshots `i32::MAX` show sup above `std::i32::MAX` and `core::i32::MAX`  If just searching for `min`, the deprecated results show up far below other things:  one page later  ~~And, as you can see, the "Deprecation planned" message shows up in the search results. The same is true for fully-deprecated items like `mem::uninitialized`: ~~ Edit: the deprecation message change was removed from this PR. Only the sorting is changed.
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 1 | ||||
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 9 | ||||
| -rw-r--r-- | src/librustdoc/html/render/search_index.rs | 23 |
3 files changed, 28 insertions, 5 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index e6a040d02e5..5ade7c8e960 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -104,6 +104,7 @@ pub(crate) struct IndexItem { pub(crate) parent_idx: Option<usize>, pub(crate) search_type: Option<IndexItemFunctionType>, pub(crate) aliases: Box<[Symbol]>, + pub(crate) deprecation: Option<Deprecation>, } /// A type used for the search index. diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 08796f10d92..577497868f6 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -470,10 +470,11 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) -> // The trailing space after each tag is to space it properly against the rest of the docs. if let Some(depr) = &item.deprecation(tcx) { - let mut message = "Deprecated"; - if !stability::deprecation_in_effect(depr) { - message = "Deprecation planned"; - } + let message = if stability::deprecation_in_effect(depr) { + "Deprecated" + } else { + "Deprecation planned" + }; tags += &tag_html("deprecated", "", message); } diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index e22ac6ec19b..146221f5806 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -40,6 +40,7 @@ pub(crate) fn build_index<'tcx>( parent_idx: None, search_type: get_function_type_for_search(item, tcx, impl_generics.as_ref(), cache), aliases: item.attrs.get_doc_aliases(), + deprecation: item.deprecation(tcx), }); } } @@ -251,7 +252,17 @@ pub(crate) fn build_index<'tcx>( )?; crate_data.serialize_field( "q", - &self.items.iter().map(|item| &item.path).collect::<Vec<_>>(), + &self + .items + .iter() + .enumerate() + // Serialize as an array of item indices and full paths + .filter_map( + |(index, item)| { + if item.path.is_empty() { None } else { Some((index, &item.path)) } + }, + ) + .collect::<Vec<_>>(), )?; crate_data.serialize_field( "d", @@ -305,6 +316,16 @@ pub(crate) fn build_index<'tcx>( .collect::<Vec<_>>(), )?; crate_data.serialize_field( + "c", + &self + .items + .iter() + .enumerate() + // Serialize as an array of deprecated item indices + .filter_map(|(index, item)| item.deprecation.map(|_| index)) + .collect::<Vec<_>>(), + )?; + crate_data.serialize_field( "p", &self.paths.iter().map(|(it, s)| (it, s.as_str())).collect::<Vec<_>>(), )?; |
