@@ -24,62 +24,37 @@ use fold::FoldItem::Strip;
24
24
25
25
/// Strip items marked `#[doc(hidden)]`
26
26
pub fn strip_hidden ( krate : clean:: Crate ) -> plugins:: PluginResult {
27
- let mut stripped = DefIdSet ( ) ;
27
+ let mut retained = DefIdSet ( ) ;
28
28
29
29
// strip all #[doc(hidden)] items
30
30
let krate = {
31
31
struct Stripper < ' a > {
32
- stripped : & ' a mut DefIdSet
32
+ retained : & ' a mut DefIdSet
33
33
}
34
34
impl < ' a > fold:: DocFolder for Stripper < ' a > {
35
35
fn fold_item ( & mut self , i : Item ) -> Option < Item > {
36
36
if i. attrs . list ( "doc" ) . has_word ( "hidden" ) {
37
37
debug ! ( "found one in strip_hidden; removing" ) ;
38
- self . stripped . insert ( i. def_id ) ;
39
-
40
38
// use a dedicated hidden item for given item type if any
41
39
match i. inner {
42
40
clean:: StructFieldItem ( ..) | clean:: ModuleItem ( ..) => {
43
41
return Strip ( i) . fold ( )
44
42
}
45
43
_ => return None ,
46
44
}
45
+ } else {
46
+ self . retained . insert ( i. def_id ) ;
47
47
}
48
48
self . fold_item_recur ( i)
49
49
}
50
50
}
51
- let mut stripper = Stripper { stripped : & mut stripped } ;
51
+ let mut stripper = Stripper { retained : & mut retained } ;
52
52
stripper. fold_crate ( krate)
53
53
} ;
54
54
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)
83
58
}
84
59
85
60
/// 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 {
101
76
krate = ImportStripper . fold_crate ( stripper. fold_crate ( krate) ) ;
102
77
}
103
78
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)
109
82
}
110
83
111
84
struct Stripper < ' a > {
@@ -204,13 +177,21 @@ impl<'a> fold::DocFolder for Stripper<'a> {
204
177
}
205
178
}
206
179
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
+
209
185
impl < ' a > fold:: DocFolder for ImplStripper < ' a > {
210
186
fn fold_item ( & mut self , i : Item ) -> Option < Item > {
211
187
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
+ }
212
193
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) {
214
195
return None ;
215
196
}
216
197
}
0 commit comments