@@ -12,43 +12,44 @@ use crate::doctree;
1212use crate :: formats:: item_type:: ItemType ;
1313use crate :: json:: types:: * ;
1414
15- impl From < clean:: Item > for Item {
15+ impl From < clean:: Item > for Option < Item > {
1616 fn from ( item : clean:: Item ) -> Self {
1717 let item_type = ItemType :: from ( & item) ;
1818 let clean:: Item {
1919 source,
2020 name,
2121 attrs,
22- kind : inner ,
22+ kind,
2323 visibility,
2424 def_id,
2525 stability : _,
2626 deprecation,
2727 } = 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+ } ) ,
5253 }
5354 }
5455}
@@ -194,10 +195,7 @@ impl From<clean::ItemKind> for ItemEnum {
194195
195196impl From < clean:: Module > for Module {
196197 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 ) }
201199 }
202200}
203201
@@ -208,7 +206,7 @@ impl From<clean::Struct> for Struct {
208206 struct_type : struct_type. into ( ) ,
209207 generics : generics. into ( ) ,
210208 fields_stripped,
211- fields : fields . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
209+ fields : ids ( fields ) ,
212210 impls : Vec :: new ( ) , // Added in JsonRenderer::item
213211 }
214212 }
@@ -221,7 +219,7 @@ impl From<clean::Union> for Struct {
221219 struct_type : struct_type. into ( ) ,
222220 generics : generics. into ( ) ,
223221 fields_stripped,
224- fields : fields . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
222+ fields : ids ( fields ) ,
225223 impls : Vec :: new ( ) , // Added in JsonRenderer::item
226224 }
227225 }
@@ -407,7 +405,7 @@ impl From<clean::Trait> for Trait {
407405 Trait {
408406 is_auto,
409407 is_unsafe : unsafety == rustc_hir:: Unsafety :: Unsafe ,
410- items : items . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
408+ items : ids ( items ) ,
411409 generics : generics. into ( ) ,
412410 bounds : bounds. into_iter ( ) . map ( Into :: into) . collect ( ) ,
413411 implementors : Vec :: new ( ) , // Added in JsonRenderer::item
@@ -434,7 +432,7 @@ impl From<clean::Impl> for Impl {
434432 provided_trait_methods : provided_trait_methods. into_iter ( ) . collect ( ) ,
435433 trait_ : trait_. map ( Into :: into) ,
436434 for_ : for_. into ( ) ,
437- items : items . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
435+ items : ids ( items ) ,
438436 negative : polarity == Some ( clean:: ImplPolarity :: Negative ) ,
439437 synthetic,
440438 blanket_impl : blanket_impl. map ( Into :: into) ,
@@ -460,7 +458,7 @@ impl From<clean::Enum> for Enum {
460458 Enum {
461459 generics : generics. into ( ) ,
462460 variants_stripped,
463- variants : variants . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
461+ variants : ids ( variants ) ,
464462 impls : Vec :: new ( ) , // Added in JsonRenderer::item
465463 }
466464 }
@@ -473,7 +471,7 @@ impl From<clean::VariantStruct> for Struct {
473471 struct_type : struct_type. into ( ) ,
474472 generics : Default :: default ( ) ,
475473 fields_stripped,
476- fields : fields . into_iter ( ) . map ( |i| i . def_id . into ( ) ) . collect ( ) ,
474+ fields : ids ( fields ) ,
477475 impls : Vec :: new ( ) ,
478476 }
479477 }
@@ -485,7 +483,7 @@ impl From<clean::Variant> for Variant {
485483 match variant. kind {
486484 CLike => Variant :: Plain ,
487485 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 ) ) ,
489487 }
490488 }
491489}
@@ -594,3 +592,7 @@ impl From<ItemType> for ItemKind {
594592 }
595593 }
596594}
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