@@ -26,14 +26,14 @@ pub trait CfgFolder: fold::Folder {
2626
2727/// A folder that strips out items that do not belong in the current
2828/// configuration.
29- struct Context < ' a , F > where F : FnMut ( & [ ast :: Attribute ] ) -> bool {
30- in_cfg : F ,
31- diagnostic : & ' a Handler ,
29+ pub struct StripUnconfigured < ' a > {
30+ diag : CfgDiagReal < ' a , ' a > ,
31+ config : & ' a ast :: CrateConfig ,
3232}
3333
34- impl < ' a , F : FnMut ( & [ ast :: Attribute ] ) -> bool > CfgFolder for Context < ' a , F > {
34+ impl < ' a > CfgFolder for StripUnconfigured < ' a > {
3535 fn configure < T : HasAttrs > ( & mut self , node : T ) -> Option < T > {
36- if ( self . in_cfg ) ( node. attrs ( ) ) {
36+ if in_cfg ( self . config , node. attrs ( ) , & mut self . diag ) {
3737 Some ( node)
3838 } else {
3939 None
@@ -43,7 +43,7 @@ impl<'a, F: FnMut(&[ast::Attribute]) -> bool> CfgFolder for Context<'a, F> {
4343 fn visit_unconfigurable_expr ( & mut self , expr : & ast:: Expr ) {
4444 if let Some ( attr) = expr. attrs ( ) . iter ( ) . find ( |a| is_cfg ( a) ) {
4545 let msg = "removing an expression is not supported in this position" ;
46- self . diagnostic . span_err ( attr. span , msg) ;
46+ self . diag . diag . span_err ( attr. span , msg) ;
4747 }
4848 }
4949}
@@ -58,16 +58,14 @@ pub fn strip_unconfigured_items(diagnostic: &Handler, krate: ast::Crate,
5858 check_for_gated_stmt_expr_attributes ( & krate, feature_gated_cfgs) ;
5959
6060 let krate = process_cfg_attr ( diagnostic, krate, feature_gated_cfgs) ;
61- let config = krate. config . clone ( ) ;
62- strip_items ( diagnostic,
63- krate,
64- |attrs| {
65- let mut diag = CfgDiagReal {
66- diag : diagnostic,
67- feature_gated_cfgs : feature_gated_cfgs,
68- } ;
69- in_cfg ( & config, attrs, & mut diag)
70- } )
61+
62+ StripUnconfigured {
63+ config : & krate. config . clone ( ) ,
64+ diag : CfgDiagReal {
65+ diag : diagnostic,
66+ feature_gated_cfgs : feature_gated_cfgs,
67+ } ,
68+ } . fold_crate ( krate)
7169}
7270
7371impl < T : CfgFolder > fold:: Folder for T {
@@ -158,17 +156,6 @@ impl<T: CfgFolder> fold::Folder for T {
158156 }
159157}
160158
161- pub fn strip_items < ' a , F > ( diagnostic : & ' a Handler ,
162- krate : ast:: Crate , in_cfg : F ) -> ast:: Crate where
163- F : FnMut ( & [ ast:: Attribute ] ) -> bool ,
164- {
165- let mut ctxt = Context {
166- in_cfg : in_cfg,
167- diagnostic : diagnostic,
168- } ;
169- ctxt. fold_crate ( krate)
170- }
171-
172159fn fold_expr < F : CfgFolder > ( folder : & mut F , expr : P < ast:: Expr > ) -> P < ast:: Expr > {
173160 expr. map ( |ast:: Expr { id, span, node, attrs} | {
174161 fold:: noop_fold_expr ( ast:: Expr {
0 commit comments