@@ -24,62 +24,37 @@ use fold::FoldItem::Strip;
2424
2525/// Strip items marked `#[doc(hidden)]`
2626pub fn strip_hidden ( krate : clean:: Crate ) -> plugins:: PluginResult {
27- let mut stripped = DefIdSet ( ) ;
27+ let mut retained = DefIdSet ( ) ;
2828
2929 // strip all #[doc(hidden)] items
3030 let krate = {
3131 struct Stripper < ' a > {
32- stripped : & ' a mut DefIdSet
32+ retained : & ' a mut DefIdSet
3333 }
3434 impl < ' a > fold:: DocFolder for Stripper < ' a > {
3535 fn fold_item ( & mut self , i : Item ) -> Option < Item > {
3636 if i. attrs . list ( "doc" ) . has_word ( "hidden" ) {
3737 debug ! ( "found one in strip_hidden; removing" ) ;
38- self . stripped . insert ( i. def_id ) ;
39-
4038 // use a dedicated hidden item for given item type if any
4139 match i. inner {
4240 clean:: StructFieldItem ( ..) | clean:: ModuleItem ( ..) => {
4341 return Strip ( i) . fold ( )
4442 }
4543 _ => return None ,
4644 }
45+ } else {
46+ self . retained . insert ( i. def_id ) ;
4747 }
4848 self . fold_item_recur ( i)
4949 }
5050 }
51- let mut stripper = Stripper { stripped : & mut stripped } ;
51+ let mut stripper = Stripper { retained : & mut retained } ;
5252 stripper. fold_crate ( krate)
5353 } ;
5454
55- // strip any traits implemented on stripped items
56- {
57- struct ImplStripper < ' a > {
58- stripped : & ' a mut DefIdSet
59- }
60- impl < ' a > fold:: DocFolder for ImplStripper < ' a > {
61- fn fold_item ( & mut self , i : Item ) -> Option < Item > {
62- if let clean:: ImplItem ( clean:: Impl {
63- for_ : clean:: ResolvedPath { did, .. } ,
64- ref trait_, ..
65- } ) = i. inner {
66- // Impls for stripped types don't need to exist
67- if self . stripped . contains ( & did) {
68- return None ;
69- }
70- // Impls of stripped traits also don't need to exist
71- if let Some ( did) = trait_. def_id ( ) {
72- if self . stripped . contains ( & did) {
73- return None ;
74- }
75- }
76- }
77- self . fold_item_recur ( i)
78- }
79- }
80- let mut stripper = ImplStripper { stripped : & mut stripped } ;
81- stripper. fold_crate ( krate)
82- }
55+ // strip all impls referencing stripped items
56+ let mut stripper = ImplStripper { retained : & retained } ;
57+ stripper. fold_crate ( krate)
8358}
8459
8560/// Strip private items from the point of view of a crate or externally from a
@@ -98,11 +73,9 @@ pub fn strip_private(mut krate: clean::Crate) -> plugins::PluginResult {
9873 krate = ImportStripper . fold_crate ( stripper. fold_crate ( krate) ) ;
9974 }
10075
101- // strip all private implementations of traits
102- {
103- let mut stripper = ImplStripper ( & retained) ;
104- stripper. fold_crate ( krate)
105- }
76+ // strip all impls referencing private items
77+ let mut stripper = ImplStripper { retained : & retained } ;
78+ stripper. fold_crate ( krate)
10679}
10780
10881struct Stripper < ' a > {
@@ -201,13 +174,21 @@ impl<'a> fold::DocFolder for Stripper<'a> {
201174 }
202175}
203176
204- // This stripper discards all private impls of traits
205- struct ImplStripper < ' a > ( & ' a DefIdSet ) ;
177+ // This stripper discards all impls which reference stripped items
178+ struct ImplStripper < ' a > {
179+ retained : & ' a DefIdSet
180+ }
181+
206182impl < ' a > fold:: DocFolder for ImplStripper < ' a > {
207183 fn fold_item ( & mut self , i : Item ) -> Option < Item > {
208184 if let clean:: ImplItem ( ref imp) = i. inner {
185+ if let Some ( did) = imp. for_ . def_id ( ) {
186+ if did. is_local ( ) && !self . retained . contains ( & did) {
187+ return None ;
188+ }
189+ }
209190 if let Some ( did) = imp. trait_ . def_id ( ) {
210- if did. is_local ( ) && !self . 0 . contains ( & did) {
191+ if did. is_local ( ) && !self . retained . contains ( & did) {
211192 return None ;
212193 }
213194 }
0 commit comments