@@ -38,7 +38,7 @@ impl JsonRenderer<'_> {
3838 Some ( UrlFragment :: UserWritten ( _) ) | None => * page_id,
3939 } ;
4040
41- ( link. clone ( ) , id_from_item_inner ( id. into ( ) , self . tcx , None , None ) )
41+ ( link. clone ( ) , id_from_item_default ( id. into ( ) , self . tcx ) )
4242 } )
4343 . collect ( ) ;
4444 let docs = item. attrs . collapsed_doc_value ( ) ;
@@ -108,7 +108,7 @@ impl JsonRenderer<'_> {
108108 Some ( ty:: Visibility :: Public ) => Visibility :: Public ,
109109 Some ( ty:: Visibility :: Restricted ( did) ) if did. is_crate_root ( ) => Visibility :: Crate ,
110110 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 ) ,
112112 path : self . tcx . def_path ( did) . to_string_no_crate_verbose ( ) ,
113113 } ,
114114 }
@@ -205,14 +205,25 @@ impl FromWithTcx<clean::TypeBindingKind> for TypeBindingKind {
205205 }
206206}
207207
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+
208213/// It generates an ID as follows:
209214///
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.
211222pub ( crate ) fn id_from_item_inner (
212223 item_id : ItemId ,
213224 tcx : TyCtxt < ' _ > ,
214- extra : Option < & Id > ,
215225 name : Option < Symbol > ,
226+ extra : Option < & Id > ,
216227) -> Id {
217228 struct DisplayDefId < ' a , ' b > ( DefId , TyCtxt < ' a > , Option < & ' b Id > , Option < Symbol > ) ;
218229
@@ -275,9 +286,9 @@ pub(crate) fn id_from_item(item: &clean::Item, tcx: TyCtxt<'_>) -> Id {
275286 clean:: ItemKind :: ImportItem ( ref import) => {
276287 let extra =
277288 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 ( ) )
279290 }
280- _ => id_from_item_inner ( item. item_id , tcx, None , item. name ) ,
291+ _ => id_from_item_inner ( item. item_id , tcx, item. name , None ) ,
281292 }
282293}
283294
@@ -551,7 +562,7 @@ impl FromWithTcx<clean::Path> for Path {
551562 fn from_tcx ( path : clean:: Path , tcx : TyCtxt < ' _ > ) -> Path {
552563 Path {
553564 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) ,
555566 args : path. segments . last ( ) . map ( |args| Box :: new ( args. clone ( ) . args . into_tcx ( tcx) ) ) ,
556567 }
557568 }
@@ -728,7 +739,7 @@ impl FromWithTcx<clean::Import> for Import {
728739 Import {
729740 source : import. source . path . whole_name ( ) ,
730741 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) ) ,
732743 glob,
733744 }
734745 }
0 commit comments