@@ -10,6 +10,7 @@ use rustc_ast::ast;
1010use rustc_hir:: def:: CtorKind ;
1111use rustc_middle:: ty:: TyCtxt ;
1212use rustc_span:: def_id:: { DefId , CRATE_DEF_INDEX } ;
13+ use rustc_span:: symbol:: Symbol ;
1314use rustc_span:: Pos ;
1415
1516use rustdoc_json_types:: * ;
@@ -25,32 +26,37 @@ impl JsonRenderer<'_> {
2526 let item_type = ItemType :: from ( & item) ;
2627 let deprecation = item. deprecation ( self . tcx ) ;
2728 let clean:: Item { source, name, attrs, kind, visibility, def_id } = item;
28- match * kind {
29- clean:: StrippedItem ( _) => None ,
30- kind => Some ( Item {
31- id : from_def_id ( def_id) ,
32- crate_id : def_id. krate . as_u32 ( ) ,
33- name : name. map ( |sym| sym. to_string ( ) ) ,
34- source : self . convert_span ( source) ,
35- visibility : self . convert_visibility ( visibility) ,
36- docs : attrs. collapsed_doc_value ( ) ,
37- links : attrs
38- . links
39- . into_iter ( )
40- . filter_map ( |clean:: ItemLink { link, did, .. } | {
41- did. map ( |did| ( link, from_def_id ( did) ) )
42- } )
43- . collect ( ) ,
44- attrs : attrs
45- . other_attrs
46- . iter ( )
47- . map ( rustc_ast_pretty:: pprust:: attribute_to_string)
48- . collect ( ) ,
49- deprecation : deprecation. map ( from_deprecation) ,
50- kind : item_type. into ( ) ,
51- inner : from_clean_item_kind ( kind, self . tcx ) ,
52- } ) ,
53- }
29+ let inner = match * kind {
30+ clean:: ItemKind :: ExternCrateItem { ref src } => ItemEnum :: ExternCrateItem {
31+ name : name. as_ref ( ) . unwrap ( ) . to_string ( ) ,
32+ rename : src. map ( |x| x. to_string ( ) ) ,
33+ } ,
34+ clean:: StrippedItem ( _) => return None ,
35+ x => from_clean_item_kind ( x, self . tcx ) ,
36+ } ;
37+ Some ( Item {
38+ id : from_def_id ( def_id) ,
39+ crate_id : def_id. krate . as_u32 ( ) ,
40+ name : name. map ( |sym| sym. to_string ( ) ) ,
41+ source : self . convert_span ( source) ,
42+ visibility : self . convert_visibility ( visibility) ,
43+ docs : attrs. collapsed_doc_value ( ) ,
44+ links : attrs
45+ . links
46+ . into_iter ( )
47+ . filter_map ( |clean:: ItemLink { link, did, .. } | {
48+ did. map ( |did| ( link, from_def_id ( did) ) )
49+ } )
50+ . collect ( ) ,
51+ attrs : attrs
52+ . other_attrs
53+ . iter ( )
54+ . map ( rustc_ast_pretty:: pprust:: attribute_to_string)
55+ . collect ( ) ,
56+ deprecation : deprecation. map ( from_deprecation) ,
57+ kind : item_type. into ( ) ,
58+ inner,
59+ } )
5460 }
5561
5662 fn convert_span ( & self , span : clean:: Span ) -> Option < Span > {
@@ -153,9 +159,6 @@ fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>) -> ItemEnum {
153159 use clean:: ItemKind :: * ;
154160 match item {
155161 ModuleItem ( m) => ItemEnum :: ModuleItem ( m. into ( ) ) ,
156- ExternCrateItem ( c, a) => {
157- ItemEnum :: ExternCrateItem { name : c. to_string ( ) , rename : a. map ( |x| x. to_string ( ) ) }
158- }
159162 ImportItem ( i) => ItemEnum :: ImportItem ( i. into ( ) ) ,
160163 StructItem ( s) => ItemEnum :: StructItem ( s. into ( ) ) ,
161164 UnionItem ( u) => ItemEnum :: UnionItem ( u. into ( ) ) ,
@@ -186,6 +189,7 @@ fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>) -> ItemEnum {
186189 PrimitiveItem ( _) | KeywordItem ( _) => {
187190 panic ! ( "{:?} is not supported for JSON output" , item)
188191 }
192+ ExternCrateItem { .. } => unreachable ! ( ) ,
189193 }
190194}
191195
0 commit comments