@@ -20,17 +20,16 @@ pub(super) type IdInterner = FxHashMap<FullItemId, types::Id>;
20
20
/// to fully disambiguate items, because sometimes we choose to split a single HIR
21
21
/// item into multiple JSON items, or have items with no coresponding HIR item.
22
22
pub ( super ) struct FullItemId {
23
- id : SingleItemId ,
23
+ /// The "main" id of the item.
24
+ ///
25
+ /// In most cases this unequely identifies the item, other fields are just
26
+ /// used for edge-cases.
27
+ def_id : DefId ,
28
+
24
29
/// An extra DefId for auto-trait-impls or blanket-impls. These don't have DefId's
25
30
/// as they're synthesized by rustdoc.
26
- extra : Option < DefId > ,
27
- }
31
+ extra_id : Option < DefId > ,
28
32
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.
33
- def_id : DefId ,
34
33
/// Needed for `rustc_doc_primitive` modules.
35
34
///
36
35
/// For these, 1 DefId is used for both the primitive and the fake-module
@@ -40,6 +39,7 @@ struct SingleItemId {
40
39
/// `--document-private-items`. Maybe we should delete that module, and
41
40
/// remove this.
42
41
name : Option < Symbol > ,
42
+
43
43
/// Used to distinguish imports of different items with the same name.
44
44
///
45
45
/// ```rust
@@ -67,39 +67,33 @@ impl JsonRenderer<'_> {
67
67
name : Option < Symbol > ,
68
68
imported_id : Option < Id > ,
69
69
) -> Id {
70
- let make_part = |def_id : DefId | {
71
- let name = match name {
72
- Some ( name) => Some ( name) ,
73
- None => {
74
- // We need this workaround because primitive types' DefId actually refers to
75
- // their parent module, which isn't present in the output JSON items. So
76
- // instead, we directly get the primitive symbol
77
- if matches ! ( self . tcx. def_kind( def_id) , DefKind :: Mod )
78
- && let Some ( prim) = self
79
- . tcx
80
- . get_attrs ( def_id, sym:: rustc_doc_primitive)
81
- . find_map ( |attr| attr. value_str ( ) )
82
- {
83
- Some ( prim)
84
- } else {
85
- self . tcx . opt_item_name ( def_id)
86
- }
87
- }
88
- } ;
89
-
90
- SingleItemId { def_id, name, imported_id }
70
+ let ( def_id, extra_id) = match item_id {
71
+ ItemId :: DefId ( did) => ( did, None ) ,
72
+ ItemId :: Blanket { for_, impl_id } => ( for_, Some ( impl_id) ) ,
73
+ ItemId :: Auto { for_, trait_ } => ( for_, Some ( trait_) ) ,
91
74
} ;
92
75
93
- let key = match item_id {
94
- ItemId :: DefId ( did) => FullItemId { id : make_part ( did) , extra : None } ,
95
- ItemId :: Blanket { for_, impl_id } => {
96
- FullItemId { id : make_part ( for_) , extra : Some ( impl_id) }
97
- }
98
- ItemId :: Auto { for_, trait_ } => {
99
- FullItemId { id : make_part ( for_) , extra : Some ( trait_) }
76
+ let name = match name {
77
+ Some ( name) => Some ( name) ,
78
+ None => {
79
+ // We need this workaround because primitive types' DefId actually refers to
80
+ // their parent module, which isn't present in the output JSON items. So
81
+ // instead, we directly get the primitive symbol
82
+ if matches ! ( self . tcx. def_kind( def_id) , DefKind :: Mod )
83
+ && let Some ( prim) = self
84
+ . tcx
85
+ . get_attrs ( def_id, sym:: rustc_doc_primitive)
86
+ . find_map ( |attr| attr. value_str ( ) )
87
+ {
88
+ Some ( prim)
89
+ } else {
90
+ self . tcx . opt_item_name ( def_id)
91
+ }
100
92
}
101
93
} ;
102
94
95
+ let key = FullItemId { def_id, extra_id, name, imported_id } ;
96
+
103
97
let mut interner = self . id_interner . borrow_mut ( ) ;
104
98
let len = interner. len ( ) ;
105
99
* interner
0 commit comments