@@ -20,17 +20,16 @@ pub(super) type IdInterner = FxHashMap<FullItemId, types::Id>;
2020/// to fully disambiguate items, because sometimes we choose to split a single HIR
2121/// item into multiple JSON items, or have items with no coresponding HIR item.
2222pub ( 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+
2429 /// An extra DefId for auto-trait-impls or blanket-impls. These don't have DefId's
2530 /// as they're synthesized by rustdoc.
26- extra : Option < DefId > ,
27- }
31+ extra_id : Option < DefId > ,
2832
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 ,
3433 /// Needed for `rustc_doc_primitive` modules.
3534 ///
3635 /// For these, 1 DefId is used for both the primitive and the fake-module
@@ -40,6 +39,7 @@ struct SingleItemId {
4039 /// `--document-private-items`. Maybe we should delete that module, and
4140 /// remove this.
4241 name : Option < Symbol > ,
42+
4343 /// Used to distinguish imports of different items with the same name.
4444 ///
4545 /// ```rust
@@ -67,39 +67,33 @@ impl JsonRenderer<'_> {
6767 name : Option < Symbol > ,
6868 imported_id : Option < Id > ,
6969 ) -> 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_) ) ,
9174 } ;
9275
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+ }
10092 }
10193 } ;
10294
95+ let key = FullItemId { def_id, extra_id, name, imported_id } ;
96+
10397 let mut interner = self . id_interner . borrow_mut ( ) ;
10498 let len = interner. len ( ) ;
10599 * interner
0 commit comments