@@ -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
@@ -98,11 +73,9 @@ pub fn strip_private(mut krate: clean::Crate) -> plugins::PluginResult {
98
73
krate = ImportStripper . fold_crate ( stripper. fold_crate ( krate) ) ;
99
74
}
100
75
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)
106
79
}
107
80
108
81
struct Stripper < ' a > {
@@ -201,13 +174,21 @@ impl<'a> fold::DocFolder for Stripper<'a> {
201
174
}
202
175
}
203
176
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
+
206
182
impl < ' a > fold:: DocFolder for ImplStripper < ' a > {
207
183
fn fold_item ( & mut self , i : Item ) -> Option < Item > {
208
184
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
+ }
209
190
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) {
211
192
return None ;
212
193
}
213
194
}
0 commit comments