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:  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:
commit
445bbde784
7 changed files with 57 additions and 1 deletions
|
@ -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)?,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue