Skip to content

[rustdoc] Correctly set up unstable items search #145386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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;

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/rustdoc-js/unstable.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this differ from tests/rustdoc-js/sort-stability.rs added by binarycat except being smaller?

Original file line number Diff line number Diff line change
@@ -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' },
],
},
];
8 changes: 8 additions & 0 deletions tests/rustdoc-js/unstable.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Loading