Skip to content

Commit 20a41fb

Browse files
committed
Use same FxHashMap in rustdoc-json-types and librustdoc.
1 parent 11dd90f commit 20a41fb

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

Cargo.lock

-2
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,6 @@ dependencies = [
20742074
"anyhow",
20752075
"clap",
20762076
"fs-err",
2077-
"rustc-hash",
20782077
"rustdoc-json-types",
20792078
"serde",
20802079
"serde_json",
@@ -4929,7 +4928,6 @@ name = "rustdoc-json-types"
49294928
version = "0.1.0"
49304929
dependencies = [
49314930
"bincode",
4932-
"rustc-hash",
49334931
"serde",
49344932
"serde_json",
49354933
]

src/librustdoc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ indexmap = "2"
1515
minifier = "0.3.0"
1616
pulldown-cmark-old = { version = "0.9.6", package = "pulldown-cmark", default-features = false }
1717
regex = "1"
18-
rustdoc-json-types = { path = "../rustdoc-json-types" }
18+
rustdoc-json-types = { path = "../rustdoc-json-types", features = ["rustc-hash"] }
1919
serde_json = "1.0"
2020
serde = { version = "1.0", features = ["derive"] }
2121
smallvec = "1.8.1"

src/librustdoc/json/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,11 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
228228
let index = (*self.index).clone().into_inner();
229229

230230
debug!("Constructing Output");
231-
// This needs to be the default HashMap for compatibility with the public interface for
232-
// rustdoc-json-types
233-
#[allow(rustc::default_hash_types)]
234231
let output = types::Crate {
235232
root: types::Id(format!("0:0:{}", e.name(self.tcx).as_u32())),
236233
crate_version: self.cache.crate_version.clone(),
237234
includes_private: self.cache.document_private,
238-
index: index.into_iter().collect(),
235+
index,
239236
paths: self
240237
.cache
241238
.paths

src/rustdoc-json-types/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ path = "lib.rs"
88

99
[dependencies]
1010
serde = { version = "1.0", features = ["derive"] }
11-
rustc-hash = "1.1.0"
11+
# rustc-hash = { version = "1.1.0", optional = true }
1212

1313
[dev-dependencies]
1414
serde_json = "1.0"
1515
bincode = "1"
16+
17+
[features]
18+
rustc-hash = []
19+

src/rustdoc-json-types/lib.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
//! These types are the public API exposed through the `--output-format json` flag. The [`Crate`]
44
//! struct is the root of the JSON blob and all other items are contained within.
55
6-
use rustc_hash::FxHashMap;
6+
#![cfg_attr(feature = "rustc-hash", feature(rustc_private))]
7+
#[cfg(feature = "rustc-hash")]
8+
extern crate rustc_hash;
9+
#[cfg(feature = "rustc-hash")]
10+
use rustc_hash::FxHashMap as HashMap;
11+
#[cfg(not(feature = "rustc-hash"))]
12+
use std::collections::HashMap;
13+
714
use serde::{Deserialize, Serialize};
815
use std::path::PathBuf;
916

@@ -23,11 +30,11 @@ pub struct Crate {
2330
pub includes_private: bool,
2431
/// A collection of all items in the local crate as well as some external traits and their
2532
/// items that are referenced locally.
26-
pub index: FxHashMap<Id, Item>,
33+
pub index: HashMap<Id, Item>,
2734
/// Maps IDs to fully qualified paths and other info helpful for generating links.
28-
pub paths: FxHashMap<Id, ItemSummary>,
35+
pub paths: HashMap<Id, ItemSummary>,
2936
/// Maps `crate_id` of items to a crate name and html_root_url if it exists.
30-
pub external_crates: FxHashMap<u32, ExternalCrate>,
37+
pub external_crates: HashMap<u32, ExternalCrate>,
3138
/// A single version number to be used in the future when making backwards incompatible changes
3239
/// to the JSON output.
3340
pub format_version: u32,
@@ -79,7 +86,7 @@ pub struct Item {
7986
/// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`).
8087
pub docs: Option<String>,
8188
/// 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
82-
pub links: FxHashMap<String, Id>,
89+
pub links: HashMap<String, Id>,
8390
/// Stringified versions of the attributes on this item (e.g. `"#[inline]"`)
8491
pub attrs: Vec<String>,
8592
pub deprecation: Option<Deprecation>,

src/tools/jsondoclint/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ edition = "2021"
99
anyhow = "1.0.62"
1010
clap = { version = "4.0.15", features = ["derive"] }
1111
fs-err = "2.8.1"
12-
rustc-hash = "1.1.0"
1312
rustdoc-json-types = { version = "0.1.0", path = "../../rustdoc-json-types" }
1413
serde = { version = "1.0", features = ["derive"] }
1514
serde_json = "1.0.85"

src/tools/jsondoclint/src/validator/tests.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn errors_on_missing_links() {
2626
root: id("0"),
2727
crate_version: None,
2828
includes_private: false,
29-
index: FxHashMap::from_iter([(
29+
index: HashMap::from_iter([(
3030
id("0"),
3131
Item {
3232
name: Some("root".to_owned()),
@@ -35,7 +35,7 @@ fn errors_on_missing_links() {
3535
span: None,
3636
visibility: Visibility::Public,
3737
docs: None,
38-
links: FxHashMap::from_iter([("Not Found".to_owned(), id("1"))]),
38+
links: HashMap::from_iter([("Not Found".to_owned(), id("1"))]),
3939
attrs: vec![],
4040
deprecation: None,
4141
inner: ItemEnum::Module(Module {
@@ -45,8 +45,8 @@ fn errors_on_missing_links() {
4545
}),
4646
},
4747
)]),
48-
paths: FxHashMap::default(),
49-
external_crates: FxHashMap::default(),
48+
paths: HashMap::default(),
49+
external_crates: HashMap::default(),
5050
format_version: rustdoc_json_types::FORMAT_VERSION,
5151
};
5252

@@ -72,7 +72,7 @@ fn errors_on_local_in_paths_and_not_index() {
7272
root: id("0:0:1572"),
7373
crate_version: None,
7474
includes_private: false,
75-
index: FxHashMap::from_iter([
75+
index: HashMap::from_iter([
7676
(
7777
id("0:0:1572"),
7878
Item {
@@ -82,7 +82,7 @@ fn errors_on_local_in_paths_and_not_index() {
8282
span: None,
8383
visibility: Visibility::Public,
8484
docs: None,
85-
links: FxHashMap::from_iter([(("prim@i32".to_owned(), id("0:1:1571")))]),
85+
links: HashMap::from_iter([(("prim@i32".to_owned(), id("0:1:1571")))]),
8686
attrs: Vec::new(),
8787
deprecation: None,
8888
inner: ItemEnum::Module(Module {
@@ -101,22 +101,22 @@ fn errors_on_local_in_paths_and_not_index() {
101101
span: None,
102102
visibility: Visibility::Public,
103103
docs: None,
104-
links: FxHashMap::default(),
104+
links: HashMap::default(),
105105
attrs: Vec::new(),
106106
deprecation: None,
107107
inner: ItemEnum::Primitive(Primitive { name: "i32".to_owned(), impls: vec![] }),
108108
},
109109
),
110110
]),
111-
paths: FxHashMap::from_iter([(
111+
paths: HashMap::from_iter([(
112112
id("0:1:1571"),
113113
ItemSummary {
114114
crate_id: 0,
115115
path: vec!["microcore".to_owned(), "i32".to_owned()],
116116
kind: ItemKind::Primitive,
117117
},
118118
)]),
119-
external_crates: FxHashMap::default(),
119+
external_crates: HashMap::default(),
120120
format_version: rustdoc_json_types::FORMAT_VERSION,
121121
};
122122

@@ -136,7 +136,7 @@ fn checks_local_crate_id_is_correct() {
136136
root: id("root"),
137137
crate_version: None,
138138
includes_private: false,
139-
index: FxHashMap::from_iter([(
139+
index: HashMap::from_iter([(
140140
id("root"),
141141
Item {
142142
id: id("root"),
@@ -145,7 +145,7 @@ fn checks_local_crate_id_is_correct() {
145145
span: None,
146146
visibility: Visibility::Public,
147147
docs: None,
148-
links: FxHashMap::default(),
148+
links: HashMap::default(),
149149
attrs: Vec::new(),
150150
deprecation: None,
151151
inner: ItemEnum::Module(Module {
@@ -155,8 +155,8 @@ fn checks_local_crate_id_is_correct() {
155155
}),
156156
},
157157
)]),
158-
paths: FxHashMap::default(),
159-
external_crates: FxHashMap::default(),
158+
paths: HashMap::default(),
159+
external_crates: HashMap::default(),
160160
format_version: FORMAT_VERSION,
161161
};
162162
check(&krate, &[]);

0 commit comments

Comments
 (0)