From be069a687a4e1c231b8ae8c68ac0444fa6fee249 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 25 Feb 2021 00:16:47 -0500 Subject: [PATCH] Remove `krate.version`; fix `crate_version` in JSON Previously, `JsonRenderer::after_krate` called `krate.version.clone()`. The problem was it did that after the version was already moved into the cache, so it would always be None. The fix was to get the version from the cache instead. --- src/librustdoc/clean/types.rs | 1 - src/librustdoc/clean/utils.rs | 1 - src/librustdoc/formats/cache.rs | 1 - src/librustdoc/json/mod.rs | 4 ++-- src/test/rustdoc-json/nested.rs | 4 +++- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 7fc48cd5f0b..09ba0e2740f 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -50,7 +50,6 @@ thread_local!(crate static MAX_DEF_IDX: RefCell> = #[derive(Clone, Debug)] crate struct Crate { crate name: Symbol, - crate version: Option, crate src: FileName, crate module: Option, crate externs: Vec<(CrateNum, ExternalCrate)>, diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 40f6c084a71..a64e8c21c46 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -77,7 +77,6 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate { Crate { name, - version: None, src, module: Some(module), externs, diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 1636af70a9a..f20296f4fe1 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -144,7 +144,6 @@ impl Cache { dst: &Path, ) -> clean::Crate { // Crawl the crate to build various caches used for the output - self.crate_version = krate.version.take(); debug!(?self.crate_version); self.traits = krate.external_traits.take(); self.masked_crates = mem::take(&mut krate.masked_crates); diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index bd5802a99dd..e6edf33d23c 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -199,7 +199,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { fn after_krate( &mut self, - krate: &clean::Crate, + _krate: &clean::Crate, _diag: &rustc_errors::Handler, ) -> Result<(), Error> { debug!("Done with crate"); @@ -210,7 +210,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { #[allow(rustc::default_hash_types)] let output = types::Crate { root: types::Id(String::from("0:0")), - crate_version: krate.version.clone(), + crate_version: self.cache.crate_version.clone(), includes_private: self.cache.document_private, index: index.into_iter().collect(), paths: self diff --git a/src/test/rustdoc-json/nested.rs b/src/test/rustdoc-json/nested.rs index a3d4935f496..5bb66f7f6fd 100644 --- a/src/test/rustdoc-json/nested.rs +++ b/src/test/rustdoc-json/nested.rs @@ -1,6 +1,8 @@ // edition:2018 +// compile-flags: --crate-version 1.0.0 -// @is nested.json "$.index[*][?(@.name=='nested')].kind" \"module\" +// @is nested.json "$.crate_version" \"1.0.0\" +// @is - "$.index[*][?(@.name=='nested')].kind" \"module\" // @is - "$.index[*][?(@.name=='nested')].inner.is_crate" true // @count - "$.index[*][?(@.name=='nested')].inner.items[*]" 1