@@ -7,28 +7,67 @@ use rustdoc_json_types::{self as types, Id}; // FIXME: Consistant.
7
7
use super :: JsonRenderer ;
8
8
use crate :: clean:: { self , ItemId } ;
9
9
10
+ pub ( super ) type IdInterner = FxHashMap < FullItemId , types:: Id > ;
11
+
10
12
#[ derive( Debug , Clone , Copy , Hash , PartialEq , Eq ) ]
13
+ /// An uninterned id.
14
+ ///
15
+ /// One of these coresponds to every:
16
+ /// 1. [`rustdoc_json_types::Item`].
17
+ /// 2. [`rustdoc_json_types::Id`] transitivly (as each `Item` has an `Id`).
18
+ ///
19
+ /// It's *broadly* equivalent to a [`DefId`], but needs slightly more information
20
+ /// to fully disambiguate items, because sometimes we choose to split a single HIR
21
+ /// item into multiple JSON items, or have items with no coresponding HIR item.
11
22
pub ( super ) struct FullItemId {
23
+ id : SingleItemId ,
24
+ /// An extra DefId for auto-trait-impls or blanket-impls. These don't have DefId's
25
+ /// as they're synthesized by rustdoc.
26
+ extra : Option < DefId > ,
27
+ }
28
+
29
+ #[ derive( Debug , Clone , Copy , Hash , PartialEq , Eq ) ]
30
+ struct SingleItemId {
31
+ /// Almost all of the "identification" comes from the `DefId`, other fields
32
+ /// are only needed in weird cases.
12
33
def_id : DefId ,
34
+ /// Needed for `rustc_doc_primitive` modules.
35
+ ///
36
+ /// For these, 1 DefId is used for both the primitive and the fake-module
37
+ /// that holds it's docs.
38
+ ///
39
+ /// N.B. This only matters when documenting the standard library with
40
+ /// `--document-private-items`. Maybe we should delete that module, and
41
+ /// remove this.
13
42
name : Option < Symbol > ,
14
- /// Used to distinguish imports of different items with the same name
15
- extra : Option < types:: Id > ,
43
+ /// Used to distinguish imports of different items with the same name.
44
+ ///
45
+ /// ```rust
46
+ /// mod module {
47
+ /// pub struct Foo {}; // Exists in type namespace
48
+ /// pub fn Foo(){} // Exists in value namespace
49
+ /// }
50
+ ///
51
+ /// pub use module::Foo; // Imports both items
52
+ /// ```
53
+ ///
54
+ /// In HIR, the `pub use` is just 1 item, but in rustdoc-json it's 2, so
55
+ /// we need to disambiguate.
56
+ imported_id : Option < types:: Id > ,
16
57
}
17
58
18
- pub ( super ) type IdInterner = FxHashMap < ( FullItemId , Option < FullItemId > ) , types:: Id > ;
19
-
20
59
impl JsonRenderer < ' _ > {
21
60
pub ( crate ) fn id_from_item_default ( & self , item_id : ItemId ) -> Id {
22
61
self . id_from_item_inner ( item_id, None , None )
23
62
}
24
63
25
- pub ( crate ) fn id_from_item_inner (
64
+ fn id_from_item_inner (
26
65
& self ,
27
66
item_id : ItemId ,
28
67
name : Option < Symbol > ,
29
- extra : Option < Id > ,
68
+ imported_id : Option < Id > ,
30
69
) -> Id {
31
- let make_part = |def_id : DefId , name : Option < Symbol > , extra : Option < Id > | {
70
+ let make_part = |def_id : DefId | {
32
71
let name = match name {
33
72
Some ( name) => Some ( name) ,
34
73
None => {
@@ -48,16 +87,16 @@ impl JsonRenderer<'_> {
48
87
}
49
88
} ;
50
89
51
- FullItemId { def_id, name, extra }
90
+ SingleItemId { def_id, name, imported_id }
52
91
} ;
53
92
54
93
let key = match item_id {
55
- ItemId :: DefId ( did) => ( make_part ( did, name , extra) , None ) ,
94
+ ItemId :: DefId ( did) => FullItemId { id : make_part ( did) , extra : None } ,
56
95
ItemId :: Blanket { for_, impl_id } => {
57
- ( make_part ( impl_id , None , None ) , Some ( make_part ( for_, name , extra) ) )
96
+ FullItemId { id : make_part ( for_) , extra : Some ( impl_id ) }
58
97
}
59
98
ItemId :: Auto { for_, trait_ } => {
60
- ( make_part ( trait_ , None , None ) , Some ( make_part ( for_, name , extra) ) )
99
+ FullItemId { id : make_part ( for_) , extra : Some ( trait_ ) }
61
100
}
62
101
} ;
63
102
0 commit comments