1
Fork 0

Rollup merge of #44989 - QuietMisdreavus:what-is-your-quest, r=GuillaumeGomez

let rustdoc print the crate version into docs

This PR adds a new unstable flag to rustdoc, `--crate-version`, which when present will add a new entry to the sidebar of the root module, printing the given version number:

![Screenshot of a test crate, showing "Version 1.3.37" under the crate name](https://user-images.githubusercontent.com/5217170/31104096-805e3f4c-a7a0-11e7-96fc-368b6fe063d6.png)

Closes #24336

(The WIP status is because i don't want to merge this until i can get the std docs to use it, which i need help from rustbuild people to make sure i get right.)
This commit is contained in:
kennytm 2017-10-12 16:14:22 +08:00
commit 445bbde784
No known key found for this signature in database
GPG key ID: FEF6C8051D0E013C
7 changed files with 57 additions and 1 deletions

View file

@ -256,6 +256,9 @@ pub struct Cache {
// the access levels from crateanalysis.
pub access_levels: Arc<AccessLevels<DefId>>,
/// The version of the crate being documented, if given fron the `--crate-version` flag.
pub crate_version: Option<String>,
// Private fields only used when initially crawling a crate to build a cache
stack: Vec<String>,
@ -534,6 +537,7 @@ pub fn run(mut krate: clean::Crate,
primitive_locations: FxHashMap(),
stripped_mod: false,
access_levels: krate.access_levels.clone(),
crate_version: krate.version.take(),
orphan_impl_items: Vec::new(),
traits: mem::replace(&mut krate.external_traits, FxHashMap()),
deref_trait_did,
@ -3433,6 +3437,16 @@ impl<'a> fmt::Display for Sidebar<'a> {
write!(fmt, "{}", it.name.as_ref().unwrap())?;
write!(fmt, "</p>")?;
if it.is_crate() {
if let Some(ref version) = cache().crate_version {
write!(fmt,
"<div class='block version'>\
<p>Version {}</p>\
</div>",
version)?;
}
}
match it.inner {
clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?,
clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?,