@@ -12,43 +12,44 @@ use crate::doctree;
12
12
use crate :: formats:: item_type:: ItemType ;
13
13
use crate :: json:: types:: * ;
14
14
15
- impl From < clean:: Item > for Item {
15
+ impl From < clean:: Item > for Option < Item > {
16
16
fn from ( item : clean:: Item ) -> Self {
17
17
let item_type = ItemType :: from ( & item) ;
18
18
let clean:: Item {
19
19
source,
20
20
name,
21
21
attrs,
22
- kind : inner ,
22
+ kind,
23
23
visibility,
24
24
def_id,
25
25
stability : _,
26
26
deprecation,
27
27
} = item;
28
- Item {
29
- id : def_id. into ( ) ,
30
- crate_id : def_id. krate . as_u32 ( ) ,
31
- name,
32
- stripped : match inner {
33
- clean:: StrippedItem ( _) => true ,
34
- _ => false ,
35
- } ,
36
- source : source. into ( ) ,
37
- visibility : visibility. into ( ) ,
38
- docs : attrs. collapsed_doc_value ( ) . unwrap_or_default ( ) ,
39
- links : attrs
40
- . links
41
- . into_iter ( )
42
- . filter_map ( |clean:: ItemLink { link, did, .. } | did. map ( |did| ( link, did. into ( ) ) ) )
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 ( Into :: into) ,
50
- kind : item_type. into ( ) ,
51
- inner : inner. into ( ) ,
28
+ match kind {
29
+ clean:: StrippedItem ( _) => None ,
30
+ _ => Some ( Item {
31
+ id : def_id. into ( ) ,
32
+ crate_id : def_id. krate . as_u32 ( ) ,
33
+ name,
34
+ source : source. into ( ) ,
35
+ visibility : visibility. into ( ) ,
36
+ docs : attrs. collapsed_doc_value ( ) . unwrap_or_default ( ) ,
37
+ links : attrs
38
+ . links
39
+ . into_iter ( )
40
+ . filter_map ( |clean:: ItemLink { link, did, .. } | {
41
+ did. map ( |did| ( link, did. into ( ) ) )
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 ( Into :: into) ,
50
+ kind : item_type. into ( ) ,
51
+ inner : kind. into ( ) ,
52
+ } ) ,
52
53
}
53
54
}
54
55
}
@@ -194,10 +195,7 @@ impl From<clean::ItemKind> for ItemEnum {
194
195
195
196
impl From < clean:: Module > for Module {
196
197
fn from ( module : clean:: Module ) -> Self {
197
- Module {
198
- is_crate : module. is_crate ,
199
- items : module. items . into_iter ( ) . map ( |i| i. def_id . into ( ) ) . collect ( ) ,
200
- }
198
+ Module { is_crate : module. is_crate , items : ids ( module. items ) }
201
199
}
202
200
}
203
201
@@ -208,7 +206,7 @@ impl From<clean::Struct> for Struct {
208
206
struct_type : struct_type. into ( ) ,
209
207
generics : generics. into ( ) ,
210
208
fields_stripped,
211
- fields : fields . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
209
+ fields : ids ( fields ) ,
212
210
impls : Vec :: new ( ) , // Added in JsonRenderer::item
213
211
}
214
212
}
@@ -221,7 +219,7 @@ impl From<clean::Union> for Struct {
221
219
struct_type : struct_type. into ( ) ,
222
220
generics : generics. into ( ) ,
223
221
fields_stripped,
224
- fields : fields . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
222
+ fields : ids ( fields ) ,
225
223
impls : Vec :: new ( ) , // Added in JsonRenderer::item
226
224
}
227
225
}
@@ -407,7 +405,7 @@ impl From<clean::Trait> for Trait {
407
405
Trait {
408
406
is_auto,
409
407
is_unsafe : unsafety == rustc_hir:: Unsafety :: Unsafe ,
410
- items : items . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
408
+ items : ids ( items ) ,
411
409
generics : generics. into ( ) ,
412
410
bounds : bounds. into_iter ( ) . map ( Into :: into) . collect ( ) ,
413
411
implementors : Vec :: new ( ) , // Added in JsonRenderer::item
@@ -434,7 +432,7 @@ impl From<clean::Impl> for Impl {
434
432
provided_trait_methods : provided_trait_methods. into_iter ( ) . collect ( ) ,
435
433
trait_ : trait_. map ( Into :: into) ,
436
434
for_ : for_. into ( ) ,
437
- items : items . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
435
+ items : ids ( items ) ,
438
436
negative : polarity == Some ( clean:: ImplPolarity :: Negative ) ,
439
437
synthetic,
440
438
blanket_impl : blanket_impl. map ( Into :: into) ,
@@ -460,7 +458,7 @@ impl From<clean::Enum> for Enum {
460
458
Enum {
461
459
generics : generics. into ( ) ,
462
460
variants_stripped,
463
- variants : variants . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
461
+ variants : ids ( variants ) ,
464
462
impls : Vec :: new ( ) , // Added in JsonRenderer::item
465
463
}
466
464
}
@@ -473,7 +471,7 @@ impl From<clean::VariantStruct> for Struct {
473
471
struct_type : struct_type. into ( ) ,
474
472
generics : Default :: default ( ) ,
475
473
fields_stripped,
476
- fields : fields . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
474
+ fields : ids ( fields ) ,
477
475
impls : Vec :: new ( ) ,
478
476
}
479
477
}
@@ -485,7 +483,7 @@ impl From<clean::Variant> for Variant {
485
483
match variant. kind {
486
484
CLike => Variant :: Plain ,
487
485
Tuple ( t) => Variant :: Tuple ( t. into_iter ( ) . map ( Into :: into) . collect ( ) ) ,
488
- Struct ( s) => Variant :: Struct ( s. fields . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ) ,
486
+ Struct ( s) => Variant :: Struct ( ids ( s. fields ) ) ,
489
487
}
490
488
}
491
489
}
@@ -594,3 +592,7 @@ impl From<ItemType> for ItemKind {
594
592
}
595
593
}
596
594
}
595
+
596
+ fn ids ( items : impl IntoIterator < Item = clean:: Item > ) -> Vec < Id > {
597
+ items. into_iter ( ) . filter ( |x| !x. is_stripped ( ) ) . map ( |i| i. def_id . into ( ) ) . collect ( )
598
+ }
0 commit comments