@@ -15,7 +15,7 @@ use std::mem;
1515
1616use clean:: { self , GetDefId , Item } ;
1717use fold;
18- use fold:: FoldItem :: Strip ;
18+ use fold:: StripItem ;
1919
2020mod collapse_docs;
2121pub use self :: collapse_docs:: collapse_docs;
@@ -35,24 +35,44 @@ pub use self::unindent_comments::unindent_comments;
3535mod propagate_doc_cfg;
3636pub use self :: propagate_doc_cfg:: propagate_doc_cfg;
3737
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
4143
4244pub 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+ ) ,
5676] ;
5777
5878pub const DEFAULT_PASSES : & ' static [ & ' static str ] = & [
@@ -79,15 +99,9 @@ pub enum DefaultPassOption {
7999
80100pub fn defaults ( default_set : DefaultPassOption ) -> & ' static [ & ' static str ] {
81101 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 => & [ ] ,
91105 }
92106}
93107
@@ -110,14 +124,21 @@ impl<'a> fold::DocFolder for Stripper<'a> {
110124 return ret;
111125 }
112126 // 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 => {
121142 if i. def_id . is_local ( ) {
122143 if !self . access_levels . is_exported ( i. def_id ) {
123144 return None ;
@@ -127,14 +148,14 @@ impl<'a> fold::DocFolder for Stripper<'a> {
127148
128149 clean:: StructFieldItem ( ..) => {
129150 if i. visibility != Some ( clean:: Public ) {
130- return Strip ( i) . fold ( ) ;
151+ return StripItem ( i) . strip ( ) ;
131152 }
132153 }
133154
134155 clean:: ModuleItem ( ..) => {
135156 if i. def_id . is_local ( ) && i. visibility != Some ( clean:: Public ) {
136157 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 ( ) ;
138159 self . update_retained = old;
139160 return ret;
140161 }
@@ -167,7 +188,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
167188 clean:: ImplItem ( ref imp) if imp. trait_ . is_some ( ) => true ,
168189 // Struct variant fields have inherited visibility
169190 clean:: VariantItem ( clean:: Variant {
170- kind : clean:: VariantKind :: Struct ( ..)
191+ kind : clean:: VariantKind :: Struct ( ..) ,
171192 } ) => true ,
172193 _ => false ,
173194 } ;
@@ -192,7 +213,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
192213
193214// This stripper discards all impls which reference stripped items
194215struct ImplStripper < ' a > {
195- retained : & ' a DefIdSet
216+ retained : & ' a DefIdSet ,
196217}
197218
198219impl < ' a > fold:: DocFolder for ImplStripper < ' a > {
@@ -203,9 +224,7 @@ impl<'a> fold::DocFolder for ImplStripper<'a> {
203224 return None ;
204225 }
205226 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) {
209228 return None ;
210229 }
211230 }
@@ -233,9 +252,12 @@ struct ImportStripper;
233252impl fold:: DocFolder for ImportStripper {
234253 fn fold_item ( & mut self , i : Item ) -> Option < Item > {
235254 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) ,
239261 }
240262 }
241263}
0 commit comments