@@ -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
@@ -101,11 +76,9 @@ pub fn strip_private(mut krate: clean::Crate) -> plugins::PluginResult {
10176 krate = ImportStripper . fold_crate ( stripper. fold_crate ( krate) ) ;
10277 }
10378
104- // strip all private implementations of traits
105- {
106- let mut stripper = ImplStripper ( & retained) ;
107- stripper. fold_crate ( krate)
108- }
79+ // strip all impls referencing private items
80+ let mut stripper = ImplStripper { retained : & retained } ;
81+ stripper. fold_crate ( krate)
10982}
11083
11184struct Stripper < ' a > {
@@ -204,13 +177,21 @@ impl<'a> fold::DocFolder for Stripper<'a> {
204177 }
205178}
206179
207- // This stripper discards all private impls of traits
208- struct ImplStripper < ' a > ( & ' a DefIdSet ) ;
180+ // This stripper discards all impls which reference stripped items
181+ struct ImplStripper < ' a > {
182+ retained : & ' a DefIdSet
183+ }
184+
209185impl < ' a > fold:: DocFolder for ImplStripper < ' a > {
210186 fn fold_item ( & mut self , i : Item ) -> Option < Item > {
211187 if let clean:: ImplItem ( ref imp) = i. inner {
188+ if let Some ( did) = imp. for_ . def_id ( ) {
189+ if did. is_local ( ) && !self . retained . contains ( & did) {
190+ return None ;
191+ }
192+ }
212193 if let Some ( did) = imp. trait_ . def_id ( ) {
213- if did. is_local ( ) && !self . 0 . contains ( & did) {
194+ if did. is_local ( ) && !self . retained . contains ( & did) {
214195 return None ;
215196 }
216197 }
0 commit comments