diff --git a/Cargo.lock b/Cargo.lock index 12be36ef86126..11ab3c9e66190 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2900,7 +2900,6 @@ dependencies = [ "anyhow", "clap 4.2.1", "fs-err", - "rustc-hash", "rustdoc-json-types", "serde", "serde_json", @@ -5543,7 +5542,6 @@ dependencies = [ name = "rustdoc-json-types" version = "0.1.0" dependencies = [ - "rustc-hash", "serde", "serde_json", ] diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 29912b95703b2..2ffb1519db612 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -13,7 +13,7 @@ itertools = "0.10.1" minifier = "0.2.2" once_cell = "1.10.0" regex = "1" -rustdoc-json-types = { path = "../rustdoc-json-types" } +rustdoc-json-types = { path = "../rustdoc-json-types", features = ["rustc_hash"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } smallvec = "1.8.1" diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index d6da6e0993894..81f974fb4eaf8 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -228,14 +228,11 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { let index = (*self.index).clone().into_inner(); debug!("Constructing Output"); - // This needs to be the default HashMap for compatibility with the public interface for - // rustdoc-json-types - #[allow(rustc::default_hash_types)] let output = types::Crate { root: types::Id(format!("0:0:{}", e.name(self.tcx).as_u32())), crate_version: self.cache.crate_version.clone(), includes_private: self.cache.document_private, - index: index.into_iter().collect(), + index, paths: self .cache .paths diff --git a/src/rustdoc-json-types/Cargo.toml b/src/rustdoc-json-types/Cargo.toml index d63caa7ad7010..fe61741f1da73 100644 --- a/src/rustdoc-json-types/Cargo.toml +++ b/src/rustdoc-json-types/Cargo.toml @@ -8,7 +8,9 @@ path = "lib.rs" [dependencies] serde = { version = "1.0", features = ["derive"] } -rustc-hash = "1.1.0" [dev-dependencies] serde_json = "1.0" + +[features] +rustc_hash = [] diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 3cf8ceed62036..e086f280d6015 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -3,7 +3,14 @@ //! These types are the public API exposed through the `--output-format json` flag. The [`Crate`] //! struct is the root of the JSON blob and all other items are contained within. -use rustc_hash::FxHashMap; +#![cfg_attr(feature = "rustc_hash", feature(rustc_private))] +#[cfg(feature = "rustc_hash")] +extern crate rustc_hash; +#[cfg(feature = "rustc_hash")] +use rustc_hash::FxHashMap as HashMap; +#[cfg(not(feature = "rustc_hash"))] +use std::collections::HashMap; + use serde::{Deserialize, Serialize}; use std::path::PathBuf; @@ -23,11 +30,11 @@ pub struct Crate { pub includes_private: bool, /// A collection of all items in the local crate as well as some external traits and their /// items that are referenced locally. - pub index: FxHashMap, + pub index: HashMap, /// Maps IDs to fully qualified paths and other info helpful for generating links. - pub paths: FxHashMap, + pub paths: HashMap, /// Maps `crate_id` of items to a crate name and html_root_url if it exists. - pub external_crates: FxHashMap, + pub external_crates: HashMap, /// A single version number to be used in the future when making backwards incompatible changes /// to the JSON output. pub format_version: u32, @@ -79,7 +86,7 @@ pub struct Item { /// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`). pub docs: Option, /// This mapping resolves [intra-doc links](https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md) from the docstring to their IDs - pub links: FxHashMap, + pub links: HashMap, /// Stringified versions of the attributes on this item (e.g. `"#[inline]"`) pub attrs: Vec, pub deprecation: Option, diff --git a/src/tools/jsondoclint/Cargo.toml b/src/tools/jsondoclint/Cargo.toml index 1318a1f447620..8990310a4f474 100644 --- a/src/tools/jsondoclint/Cargo.toml +++ b/src/tools/jsondoclint/Cargo.toml @@ -9,7 +9,6 @@ edition = "2021" anyhow = "1.0.62" clap = { version = "4.0.15", features = ["derive"] } fs-err = "2.8.1" -rustc-hash = "1.1.0" rustdoc-json-types = { version = "0.1.0", path = "../../rustdoc-json-types" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.85" diff --git a/src/tools/jsondoclint/src/validator/tests.rs b/src/tools/jsondoclint/src/validator/tests.rs index 95a56a9dfac45..29563d7e0d250 100644 --- a/src/tools/jsondoclint/src/validator/tests.rs +++ b/src/tools/jsondoclint/src/validator/tests.rs @@ -1,5 +1,5 @@ -use rustc_hash::FxHashMap; use rustdoc_json_types::{Crate, Item, ItemKind, ItemSummary, Visibility, FORMAT_VERSION}; +use std::collections::HashMap; use crate::json_find::SelectorPart; @@ -26,7 +26,7 @@ fn errors_on_missing_links() { root: id("0"), crate_version: None, includes_private: false, - index: FxHashMap::from_iter([( + index: HashMap::from_iter([( id("0"), Item { name: Some("root".to_owned()), @@ -35,7 +35,7 @@ fn errors_on_missing_links() { span: None, visibility: Visibility::Public, docs: None, - links: FxHashMap::from_iter([("Not Found".to_owned(), id("1"))]), + links: HashMap::from_iter([("Not Found".to_owned(), id("1"))]), attrs: vec![], deprecation: None, inner: ItemEnum::Module(Module { @@ -45,8 +45,8 @@ fn errors_on_missing_links() { }), }, )]), - paths: FxHashMap::default(), - external_crates: FxHashMap::default(), + paths: HashMap::default(), + external_crates: HashMap::default(), format_version: rustdoc_json_types::FORMAT_VERSION, }; @@ -72,7 +72,7 @@ fn errors_on_local_in_paths_and_not_index() { root: id("0:0:1572"), crate_version: None, includes_private: false, - index: FxHashMap::from_iter([ + index: HashMap::from_iter([ ( id("0:0:1572"), Item { @@ -82,7 +82,7 @@ fn errors_on_local_in_paths_and_not_index() { span: None, visibility: Visibility::Public, docs: None, - links: FxHashMap::from_iter([(("prim@i32".to_owned(), id("0:1:1571")))]), + links: HashMap::from_iter([(("prim@i32".to_owned(), id("0:1:1571")))]), attrs: Vec::new(), deprecation: None, inner: ItemEnum::Module(Module { @@ -101,14 +101,14 @@ fn errors_on_local_in_paths_and_not_index() { span: None, visibility: Visibility::Public, docs: None, - links: FxHashMap::default(), + links: HashMap::default(), attrs: Vec::new(), deprecation: None, inner: ItemEnum::Primitive(Primitive { name: "i32".to_owned(), impls: vec![] }), }, ), ]), - paths: FxHashMap::from_iter([( + paths: HashMap::from_iter([( id("0:1:1571"), ItemSummary { crate_id: 0, @@ -116,7 +116,7 @@ fn errors_on_local_in_paths_and_not_index() { kind: ItemKind::Primitive, }, )]), - external_crates: FxHashMap::default(), + external_crates: HashMap::default(), format_version: rustdoc_json_types::FORMAT_VERSION, }; @@ -136,7 +136,7 @@ fn checks_local_crate_id_is_correct() { root: id("root"), crate_version: None, includes_private: false, - index: FxHashMap::from_iter([( + index: HashMap::from_iter([( id("root"), Item { id: id("root"), @@ -145,7 +145,7 @@ fn checks_local_crate_id_is_correct() { span: None, visibility: Visibility::Public, docs: None, - links: FxHashMap::default(), + links: HashMap::default(), attrs: Vec::new(), deprecation: None, inner: ItemEnum::Module(Module { @@ -155,8 +155,8 @@ fn checks_local_crate_id_is_correct() { }), }, )]), - paths: FxHashMap::default(), - external_crates: FxHashMap::default(), + paths: HashMap::default(), + external_crates: HashMap::default(), format_version: FORMAT_VERSION, }; check(&krate, &[]);