@@ -15,7 +15,7 @@ use std::mem;
15
15
16
16
use clean:: { self , GetDefId , Item } ;
17
17
use fold;
18
- use fold:: FoldItem :: Strip ;
18
+ use fold:: StripItem ;
19
19
20
20
mod collapse_docs;
21
21
pub use self :: collapse_docs:: collapse_docs;
@@ -35,24 +35,44 @@ pub use self::unindent_comments::unindent_comments;
35
35
mod propagate_doc_cfg;
36
36
pub use self :: propagate_doc_cfg:: propagate_doc_cfg;
37
37
38
- type Pass = ( & ' static str , // name
39
- fn ( clean:: Crate ) -> clean:: Crate , // fn
40
- & ' static str ) ; // description
38
+ type Pass = (
39
+ & ' static str , // name
40
+ fn ( clean:: Crate ) -> clean:: Crate , // fn
41
+ & ' static str ,
42
+ ) ; // description
41
43
42
44
pub const PASSES : & ' static [ Pass ] = & [
43
- ( "strip-hidden" , strip_hidden,
44
- "strips all doc(hidden) items from the output" ) ,
45
- ( "unindent-comments" , unindent_comments,
46
- "removes excess indentation on comments in order for markdown to like it" ) ,
47
- ( "collapse-docs" , collapse_docs,
48
- "concatenates all document attributes into one document attribute" ) ,
49
- ( "strip-private" , strip_private,
50
- "strips all private items from a crate which cannot be seen externally, \
51
- implies strip-priv-imports") ,
52
- ( "strip-priv-imports" , strip_priv_imports,
53
- "strips all private import statements (`use`, `extern crate`) from a crate" ) ,
54
- ( "propagate-doc-cfg" , propagate_doc_cfg,
55
- "propagates `#[doc(cfg(...))]` to child items" ) ,
45
+ (
46
+ "strip-hidden" ,
47
+ strip_hidden,
48
+ "strips all doc(hidden) items from the output" ,
49
+ ) ,
50
+ (
51
+ "unindent-comments" ,
52
+ unindent_comments,
53
+ "removes excess indentation on comments in order for markdown to like it" ,
54
+ ) ,
55
+ (
56
+ "collapse-docs" ,
57
+ collapse_docs,
58
+ "concatenates all document attributes into one document attribute" ,
59
+ ) ,
60
+ (
61
+ "strip-private" ,
62
+ strip_private,
63
+ "strips all private items from a crate which cannot be seen externally, \
64
+ implies strip-priv-imports",
65
+ ) ,
66
+ (
67
+ "strip-priv-imports" ,
68
+ strip_priv_imports,
69
+ "strips all private import statements (`use`, `extern crate`) from a crate" ,
70
+ ) ,
71
+ (
72
+ "propagate-doc-cfg" ,
73
+ propagate_doc_cfg,
74
+ "propagates `#[doc(cfg(...))]` to child items" ,
75
+ ) ,
56
76
] ;
57
77
58
78
pub const DEFAULT_PASSES : & ' static [ & ' static str ] = & [
@@ -79,15 +99,9 @@ pub enum DefaultPassOption {
79
99
80
100
pub fn defaults ( default_set : DefaultPassOption ) -> & ' static [ & ' static str ] {
81
101
match default_set {
82
- DefaultPassOption :: Default => {
83
- DEFAULT_PASSES
84
- } ,
85
- DefaultPassOption :: Private => {
86
- DEFAULT_PRIVATE_PASSES
87
- } ,
88
- DefaultPassOption :: None => {
89
- & [ ]
90
- } ,
102
+ DefaultPassOption :: Default => DEFAULT_PASSES ,
103
+ DefaultPassOption :: Private => DEFAULT_PRIVATE_PASSES ,
104
+ DefaultPassOption :: None => & [ ] ,
91
105
}
92
106
}
93
107
@@ -110,14 +124,21 @@ impl<'a> fold::DocFolder for Stripper<'a> {
110
124
return ret;
111
125
}
112
126
// These items can all get re-exported
113
- clean:: ExistentialItem ( ..) |
114
- clean:: TypedefItem ( ..) | clean:: StaticItem ( ..) |
115
- clean:: StructItem ( ..) | clean:: EnumItem ( ..) |
116
- clean:: TraitItem ( ..) | clean:: FunctionItem ( ..) |
117
- clean:: VariantItem ( ..) | clean:: MethodItem ( ..) |
118
- clean:: ForeignFunctionItem ( ..) | clean:: ForeignStaticItem ( ..) |
119
- clean:: ConstantItem ( ..) | clean:: UnionItem ( ..) |
120
- clean:: AssociatedConstItem ( ..) | clean:: ForeignTypeItem => {
127
+ clean:: ExistentialItem ( ..)
128
+ | clean:: TypedefItem ( ..)
129
+ | clean:: StaticItem ( ..)
130
+ | clean:: StructItem ( ..)
131
+ | clean:: EnumItem ( ..)
132
+ | clean:: TraitItem ( ..)
133
+ | clean:: FunctionItem ( ..)
134
+ | clean:: VariantItem ( ..)
135
+ | clean:: MethodItem ( ..)
136
+ | clean:: ForeignFunctionItem ( ..)
137
+ | clean:: ForeignStaticItem ( ..)
138
+ | clean:: ConstantItem ( ..)
139
+ | clean:: UnionItem ( ..)
140
+ | clean:: AssociatedConstItem ( ..)
141
+ | clean:: ForeignTypeItem => {
121
142
if i. def_id . is_local ( ) {
122
143
if !self . access_levels . is_exported ( i. def_id ) {
123
144
return None ;
@@ -127,14 +148,14 @@ impl<'a> fold::DocFolder for Stripper<'a> {
127
148
128
149
clean:: StructFieldItem ( ..) => {
129
150
if i. visibility != Some ( clean:: Public ) {
130
- return Strip ( i) . fold ( ) ;
151
+ return StripItem ( i) . strip ( ) ;
131
152
}
132
153
}
133
154
134
155
clean:: ModuleItem ( ..) => {
135
156
if i. def_id . is_local ( ) && i. visibility != Some ( clean:: Public ) {
136
157
let old = mem:: replace ( & mut self . update_retained , false ) ;
137
- let ret = Strip ( self . fold_item_recur ( i) . unwrap ( ) ) . fold ( ) ;
158
+ let ret = StripItem ( self . fold_item_recur ( i) . unwrap ( ) ) . strip ( ) ;
138
159
self . update_retained = old;
139
160
return ret;
140
161
}
@@ -167,7 +188,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
167
188
clean:: ImplItem ( ref imp) if imp. trait_ . is_some ( ) => true ,
168
189
// Struct variant fields have inherited visibility
169
190
clean:: VariantItem ( clean:: Variant {
170
- kind : clean:: VariantKind :: Struct ( ..)
191
+ kind : clean:: VariantKind :: Struct ( ..) ,
171
192
} ) => true ,
172
193
_ => false ,
173
194
} ;
@@ -192,7 +213,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
192
213
193
214
// This stripper discards all impls which reference stripped items
194
215
struct ImplStripper < ' a > {
195
- retained : & ' a DefIdSet
216
+ retained : & ' a DefIdSet ,
196
217
}
197
218
198
219
impl < ' a > fold:: DocFolder for ImplStripper < ' a > {
@@ -203,9 +224,7 @@ impl<'a> fold::DocFolder for ImplStripper<'a> {
203
224
return None ;
204
225
}
205
226
if let Some ( did) = imp. for_ . def_id ( ) {
206
- if did. is_local ( ) && !imp. for_ . is_generic ( ) &&
207
- !self . retained . contains ( & did)
208
- {
227
+ if did. is_local ( ) && !imp. for_ . is_generic ( ) && !self . retained . contains ( & did) {
209
228
return None ;
210
229
}
211
230
}
@@ -233,9 +252,12 @@ struct ImportStripper;
233
252
impl fold:: DocFolder for ImportStripper {
234
253
fn fold_item ( & mut self , i : Item ) -> Option < Item > {
235
254
match i. inner {
236
- clean:: ExternCrateItem ( ..) |
237
- clean:: ImportItem ( ..) if i. visibility != Some ( clean:: Public ) => None ,
238
- _ => self . fold_item_recur ( i)
255
+ clean:: ExternCrateItem ( ..) | clean:: ImportItem ( ..)
256
+ if i. visibility != Some ( clean:: Public ) =>
257
+ {
258
+ None
259
+ }
260
+ _ => self . fold_item_recur ( i) ,
239
261
}
240
262
}
241
263
}
0 commit comments