@@ -25,32 +25,37 @@ impl JsonRenderer<'_> {
25
25
let item_type = ItemType :: from ( & item) ;
26
26
let deprecation = item. deprecation ( self . tcx ) ;
27
27
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
- }
28
+ let inner = match * kind {
29
+ clean:: ItemKind :: ExternCrateItem { ref src } => ItemEnum :: ExternCrateItem {
30
+ name : name. as_ref ( ) . unwrap ( ) . to_string ( ) ,
31
+ rename : src. map ( |x| x. to_string ( ) ) ,
32
+ } ,
33
+ clean:: StrippedItem ( _) => return None ,
34
+ x => from_clean_item_kind ( x, self . tcx ) ,
35
+ } ;
36
+ Some ( Item {
37
+ id : from_def_id ( def_id) ,
38
+ crate_id : def_id. krate . as_u32 ( ) ,
39
+ name : name. map ( |sym| sym. to_string ( ) ) ,
40
+ source : self . convert_span ( source) ,
41
+ visibility : self . convert_visibility ( visibility) ,
42
+ docs : attrs. collapsed_doc_value ( ) ,
43
+ links : attrs
44
+ . links
45
+ . into_iter ( )
46
+ . filter_map ( |clean:: ItemLink { link, did, .. } | {
47
+ did. map ( |did| ( link, from_def_id ( did) ) )
48
+ } )
49
+ . collect ( ) ,
50
+ attrs : attrs
51
+ . other_attrs
52
+ . iter ( )
53
+ . map ( rustc_ast_pretty:: pprust:: attribute_to_string)
54
+ . collect ( ) ,
55
+ deprecation : deprecation. map ( from_deprecation) ,
56
+ kind : item_type. into ( ) ,
57
+ inner,
58
+ } )
54
59
}
55
60
56
61
fn convert_span ( & self , span : clean:: Span ) -> Option < Span > {
@@ -153,9 +158,6 @@ fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>) -> ItemEnum {
153
158
use clean:: ItemKind :: * ;
154
159
match item {
155
160
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
- }
159
161
ImportItem ( i) => ItemEnum :: ImportItem ( i. into ( ) ) ,
160
162
StructItem ( s) => ItemEnum :: StructItem ( s. into ( ) ) ,
161
163
UnionItem ( u) => ItemEnum :: UnionItem ( u. into ( ) ) ,
@@ -186,6 +188,7 @@ fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>) -> ItemEnum {
186
188
PrimitiveItem ( _) | KeywordItem ( _) => {
187
189
panic ! ( "{:?} is not supported for JSON output" , item)
188
190
}
191
+ ExternCrateItem { .. } => unreachable ! ( ) ,
189
192
}
190
193
}
191
194
0 commit comments