@@ -10,6 +10,7 @@ use rustc_ast::ast;
10
10
use rustc_hir:: def:: CtorKind ;
11
11
use rustc_middle:: ty:: TyCtxt ;
12
12
use rustc_span:: def_id:: { DefId , CRATE_DEF_INDEX } ;
13
+ use rustc_span:: symbol:: Symbol ;
13
14
use rustc_span:: Pos ;
14
15
15
16
use rustdoc_json_types:: * ;
@@ -25,32 +26,37 @@ impl JsonRenderer<'_> {
25
26
let item_type = ItemType :: from ( & item) ;
26
27
let deprecation = item. deprecation ( self . tcx ) ;
27
28
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
+ } )
54
60
}
55
61
56
62
fn convert_span ( & self , span : clean:: Span ) -> Option < Span > {
@@ -153,9 +159,6 @@ fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>) -> ItemEnum {
153
159
use clean:: ItemKind :: * ;
154
160
match item {
155
161
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
162
ImportItem ( i) => ItemEnum :: ImportItem ( i. into ( ) ) ,
160
163
StructItem ( s) => ItemEnum :: StructItem ( s. into ( ) ) ,
161
164
UnionItem ( u) => ItemEnum :: UnionItem ( u. into ( ) ) ,
@@ -186,6 +189,7 @@ fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>) -> ItemEnum {
186
189
PrimitiveItem ( _) | KeywordItem ( _) => {
187
190
panic ! ( "{:?} is not supported for JSON output" , item)
188
191
}
192
+ ExternCrateItem { .. } => unreachable ! ( ) ,
189
193
}
190
194
}
191
195
0 commit comments