Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
);
let aliases = item.attrs.get_doc_aliases();
let deprecation = item.deprecation(tcx);
let stability = item.stability(tcx);
let index_item = IndexItem {
ty: item.type_(),
defid: Some(defid),
Expand All @@ -609,6 +610,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
search_type,
aliases,
deprecation,
stability,
};

cache.search_index.push(index_item);
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub(crate) struct IndexItem {
pub(crate) search_type: Option<IndexItemFunctionType>,
pub(crate) aliases: Box<[Symbol]>,
pub(crate) deprecation: Option<Deprecation>,
pub(crate) stability: Option<rustc_hir::Stability>,
}

/// A type used for the search index.
Expand Down
9 changes: 9 additions & 0 deletions src/librustdoc/html/render/search_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ impl SerializedSearchIndex {
parent,
trait_parent,
deprecated,
unstable,
associated_item_disambiguator,
}| EntryData {
krate: *map.get(krate).unwrap(),
Expand All @@ -621,6 +622,7 @@ impl SerializedSearchIndex {
parent: parent.and_then(|path_id| map.get(&path_id).copied()),
trait_parent: trait_parent.and_then(|path_id| map.get(&path_id).copied()),
deprecated: *deprecated,
unstable: *unstable,
associated_item_disambiguator: associated_item_disambiguator.clone(),
},
),
Expand Down Expand Up @@ -889,6 +891,7 @@ struct EntryData {
parent: Option<usize>,
trait_parent: Option<usize>,
deprecated: bool,
unstable: bool,
associated_item_disambiguator: Option<String>,
}

Expand All @@ -905,6 +908,7 @@ impl Serialize for EntryData {
seq.serialize_element(&self.parent.map(|id| id + 1).unwrap_or(0))?;
seq.serialize_element(&self.trait_parent.map(|id| id + 1).unwrap_or(0))?;
seq.serialize_element(&if self.deprecated { 1 } else { 0 })?;
seq.serialize_element(&if self.unstable { 1 } else { 0 })?;
if let Some(disambig) = &self.associated_item_disambiguator {
seq.serialize_element(&disambig)?;
}
Expand Down Expand Up @@ -939,6 +943,7 @@ impl<'de> Deserialize<'de> for EntryData {
v.next_element()?.ok_or_else(|| A::Error::missing_field("trait_parent"))?;

let deprecated: u32 = v.next_element()?.unwrap_or(0);
let unstable: u32 = v.next_element()?.unwrap_or(0);
let associated_item_disambiguator: Option<String> = v.next_element()?;
Ok(EntryData {
krate,
Expand All @@ -949,6 +954,7 @@ impl<'de> Deserialize<'de> for EntryData {
parent: Option::<i32>::from(parent).map(|path| path as usize),
trait_parent: Option::<i32>::from(trait_parent).map(|path| path as usize),
deprecated: deprecated != 0,
unstable: unstable != 0,
associated_item_disambiguator,
})
}
Expand Down Expand Up @@ -1275,6 +1281,7 @@ pub(crate) fn build_index(
),
aliases: item.attrs.get_doc_aliases(),
deprecation: item.deprecation(tcx),
stability: item.stability(tcx),
});
}
}
Expand Down Expand Up @@ -1370,6 +1377,7 @@ pub(crate) fn build_index(
parent: None,
trait_parent: None,
deprecated: false,
unstable: false,
associated_item_disambiguator: None,
}),
crate_doc,
Expand Down Expand Up @@ -1508,6 +1516,7 @@ pub(crate) fn build_index(
module_path,
exact_module_path,
deprecated: item.deprecation.is_some(),
unstable: item.stability.is_some_and(|x| x.is_unstable()),
associated_item_disambiguator: if let Some(impl_id) = item.impl_id
&& let Some(parent_idx) = item.parent_idx
&& associated_item_duplicates
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/html/static/js/rustdoc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ declare namespace rustdoc {

/**
* A single parsed "atom" in a search query. For example,
*
*
* std::fmt::Formatter, Write -> Result<()>
* ┏━━━━━━━━━━━━━━━━━━ ┌──── ┏━━━━━┅┅┅┅┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┐
* ┃ │ ┗ QueryElement { ┊
Expand Down Expand Up @@ -243,6 +243,7 @@ declare namespace rustdoc {
parent: number?,
traitParent: number?,
deprecated: boolean,
unstable: boolean,
associatedItemDisambiguator: string?,
}

Expand Down Expand Up @@ -292,6 +293,7 @@ declare namespace rustdoc {
path: PathData?,
functionData: FunctionData?,
deprecated: boolean,
unstable: boolean,
parent: RowParent,
traitParent: RowParent,
}
Expand Down
13 changes: 12 additions & 1 deletion src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,7 @@ class DocSearch {
* parent,
* trait_parent,
* deprecated,
* unstable,
* associated_item_disambiguator
* @type {rustdoc.ArrayWithOptionals<[
* number,
Expand All @@ -1642,6 +1643,7 @@ class DocSearch {
* number,
* number,
* number,
* number,
* ], [string]>}
*/
const raw = JSON.parse(encoded);
Expand All @@ -1653,7 +1655,8 @@ class DocSearch {
parent: raw[4] === 0 ? null : raw[4] - 1,
traitParent: raw[5] === 0 ? null : raw[5] - 1,
deprecated: raw[6] === 1 ? true : false,
associatedItemDisambiguator: raw.length === 7 ? null : raw[7],
unstable: raw[7] === 1 ? true : false,
associatedItemDisambiguator: raw.length === 8 ? null : raw[8],
};
}

Expand Down Expand Up @@ -1946,6 +1949,7 @@ class DocSearch {
path,
functionData,
deprecated: entry ? entry.deprecated : false,
unstable: entry ? entry.unstable : false,
parent,
traitParent,
};
Expand Down Expand Up @@ -2867,6 +2871,13 @@ class DocSearch {
return a - b;
}

// sort unstable items later
Copy link
Member

Choose a reason for hiding this comment

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

That confirms that title is wrong. 😉

a = Number(aai.unstable);
b = Number(bbi.unstable);
if (a !== b) {
return a - b;
}

// sort by crate (current crate comes first)
a = Number(aai.crate !== preferredCrate);
b = Number(bbi.crate !== preferredCrate);
Expand Down
9 changes: 9 additions & 0 deletions tests/rustdoc-js/sort-stability.js
Copy link
Contributor

Choose a reason for hiding this comment

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

The PR title says it sorts unstable items first. This test seems to show the unstable item appearing last. Which is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pr title was a typo, fixed (need to go back and fix the commit description too)

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const EXPECTED = [
{
'query': 'foo',
'others': [
{"path": "sort_stability::old", "name": "foo"},
{"path": "sort_stability::new", "name": "foo"},
],
},
];
16 changes: 16 additions & 0 deletions tests/rustdoc-js/sort-stability.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![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() {}
}
Loading