@@ -38,7 +38,7 @@ impl JsonRenderer<'_> {
38
38
Some ( UrlFragment :: UserWritten ( _) ) | None => * page_id,
39
39
} ;
40
40
41
- ( link. clone ( ) , id_from_item_inner ( id. into ( ) , self . tcx , None , None ) )
41
+ ( link. clone ( ) , id_from_item_default ( id. into ( ) , self . tcx ) )
42
42
} )
43
43
. collect ( ) ;
44
44
let docs = item. attrs . collapsed_doc_value ( ) ;
@@ -108,7 +108,7 @@ impl JsonRenderer<'_> {
108
108
Some ( ty:: Visibility :: Public ) => Visibility :: Public ,
109
109
Some ( ty:: Visibility :: Restricted ( did) ) if did. is_crate_root ( ) => Visibility :: Crate ,
110
110
Some ( ty:: Visibility :: Restricted ( did) ) => Visibility :: Restricted {
111
- parent : id_from_item_inner ( did. into ( ) , self . tcx , None , None ) ,
111
+ parent : id_from_item_default ( did. into ( ) , self . tcx ) ,
112
112
path : self . tcx . def_path ( did) . to_string_no_crate_verbose ( ) ,
113
113
} ,
114
114
}
@@ -205,14 +205,25 @@ impl FromWithTcx<clean::TypeBindingKind> for TypeBindingKind {
205
205
}
206
206
}
207
207
208
+ #[ inline]
209
+ pub ( crate ) fn id_from_item_default ( item_id : ItemId , tcx : TyCtxt < ' _ > ) -> Id {
210
+ id_from_item_inner ( item_id, tcx, None , None )
211
+ }
212
+
208
213
/// It generates an ID as follows:
209
214
///
210
- /// `CRATE_ID:ITEM_ID[:NAME_ID]` (if there is no name, NAME_ID is not generated).
215
+ /// `CRATE_ID:ITEM_ID[:NAME_ID][-EXTRA]`:
216
+ /// * If there is no `name`, `NAME_ID` is not generated.
217
+ /// * If there is no `extra`, `EXTRA` is not generated.
218
+ ///
219
+ /// * `name` is the item's name if available (it's not for impl blocks for example).
220
+ /// * `extra` is used for reexports: it contains the ID of the reexported item. It is used to allow
221
+ /// to have items with the same name but different types to both appear in the generated JSON.
211
222
pub ( crate ) fn id_from_item_inner (
212
223
item_id : ItemId ,
213
224
tcx : TyCtxt < ' _ > ,
214
- extra : Option < & Id > ,
215
225
name : Option < Symbol > ,
226
+ extra : Option < & Id > ,
216
227
) -> Id {
217
228
struct DisplayDefId < ' a , ' b > ( DefId , TyCtxt < ' a > , Option < & ' b Id > , Option < Symbol > ) ;
218
229
@@ -275,9 +286,9 @@ pub(crate) fn id_from_item(item: &clean::Item, tcx: TyCtxt<'_>) -> Id {
275
286
clean:: ItemKind :: ImportItem ( ref import) => {
276
287
let extra =
277
288
import. source . did . map ( ItemId :: from) . map ( |i| id_from_item_inner ( i, tcx, None , None ) ) ;
278
- id_from_item_inner ( item. item_id , tcx, extra. as_ref ( ) , item . name )
289
+ id_from_item_inner ( item. item_id , tcx, item . name , extra. as_ref ( ) )
279
290
}
280
- _ => id_from_item_inner ( item. item_id , tcx, None , item. name ) ,
291
+ _ => id_from_item_inner ( item. item_id , tcx, item. name , None ) ,
281
292
}
282
293
}
283
294
@@ -551,7 +562,7 @@ impl FromWithTcx<clean::Path> for Path {
551
562
fn from_tcx ( path : clean:: Path , tcx : TyCtxt < ' _ > ) -> Path {
552
563
Path {
553
564
name : path. whole_name ( ) ,
554
- id : id_from_item_inner ( path. def_id ( ) . into ( ) , tcx, None , None ) ,
565
+ id : id_from_item_default ( path. def_id ( ) . into ( ) , tcx) ,
555
566
args : path. segments . last ( ) . map ( |args| Box :: new ( args. clone ( ) . args . into_tcx ( tcx) ) ) ,
556
567
}
557
568
}
@@ -728,7 +739,7 @@ impl FromWithTcx<clean::Import> for Import {
728
739
Import {
729
740
source : import. source . path . whole_name ( ) ,
730
741
name,
731
- id : import. source . did . map ( ItemId :: from) . map ( |i| id_from_item_inner ( i, tcx, None , None ) ) ,
742
+ id : import. source . did . map ( ItemId :: from) . map ( |i| id_from_item_default ( i, tcx) ) ,
732
743
glob,
733
744
}
734
745
}
0 commit comments