You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use same FxHashMap in rustdoc-json-types and librustdoc.
The original motivation was me trying to remove the
`#![allow(rustc::default_hash_types)]`, as after #108626, we should be using
`FxHashMap` here. I then realized I should also be able to remove the
`.into_iter().collect()`, as we no longer need to convert from `FxHashMap` to `std::HashMap`.
However, this didn't work, and I got the following error
```
error[E0308]: mismatched types
--> src/librustdoc/json/mod.rs:235:13
|
235 | index,
| ^^^^^ expected `rustc_hash::FxHasher`, found `FxHasher`
|
= note: `FxHasher` and `rustc_hash::FxHasher` have similar names, but are actually distinct types
note: `FxHasher` is defined in crate `rustc_hash`
--> /cargo/registry/src/index.crates.io-6f17d22bba15001f/rustc-hash-1.1.0/src/lib.rs:60:1
note: `rustc_hash::FxHasher` is defined in crate `rustc_hash`
--> /home/alona/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustc-hash-1.1.0/src/lib.rs:60:1
|
60 | pub struct FxHasher {
| ^^^^^^^^^^^^^^^^^^^
= note: perhaps two different versions of crate `rustc_hash` are being used?
```
This is because `librustdoc` got it's `FxHashMap` via the sysroot
`rustc-data-strucures`, whereas `rustdoc-json-types` got it via
`rustc-hash` on crates.io.
To avoid this, `rustdoc-json-types` now uses
`#![feature(rustc_private)]` to load the same version as `librustdoc`.
However, this needs to be placed behind a feature, as
`rustdoc-json-types` is also dependency of `src/tools/jsondocck`, which
means need needs to be buildable without nightly features.
Copy file name to clipboardexpand all lines: src/rustdoc-json-types/lib.rs
+9-5
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,11 @@
3
3
//! These types are the public API exposed through the `--output-format json` flag. The [`Crate`]
4
4
//! struct is the root of the JSON blob and all other items are contained within.
5
5
6
-
use rustc_hash::FxHashMap;
6
+
#[cfg(feature = "rustc-hash")]
7
+
use rustc_hash::FxHashMapasHashMap;
8
+
#[cfg(not(feature = "rustc-hash"))]
9
+
use std::collections::HashMap;
10
+
7
11
use serde::{Deserialize,Serialize};
8
12
use std::path::PathBuf;
9
13
@@ -23,11 +27,11 @@ pub struct Crate {
23
27
pubincludes_private:bool,
24
28
/// A collection of all items in the local crate as well as some external traits and their
25
29
/// items that are referenced locally.
26
-
pubindex:FxHashMap<Id,Item>,
30
+
pubindex:HashMap<Id,Item>,
27
31
/// Maps IDs to fully qualified paths and other info helpful for generating links.
28
-
pubpaths:FxHashMap<Id,ItemSummary>,
32
+
pubpaths:HashMap<Id,ItemSummary>,
29
33
/// Maps `crate_id` of items to a crate name and html_root_url if it exists.
30
-
pubexternal_crates:FxHashMap<u32,ExternalCrate>,
34
+
pubexternal_crates:HashMap<u32,ExternalCrate>,
31
35
/// A single version number to be used in the future when making backwards incompatible changes
32
36
/// to the JSON output.
33
37
pubformat_version:u32,
@@ -79,7 +83,7 @@ pub struct Item {
79
83
/// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`).
80
84
pubdocs:Option<String>,
81
85
/// 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
-
publinks:FxHashMap<String,Id>,
86
+
publinks:HashMap<String,Id>,
83
87
/// Stringified versions of the attributes on this item (e.g. `"#[inline]"`)
0 commit comments