@@ -26,14 +26,14 @@ pub trait CfgFolder: fold::Folder {
26
26
27
27
/// A folder that strips out items that do not belong in the current
28
28
/// 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 ,
32
32
}
33
33
34
- impl < ' a , F : FnMut ( & [ ast :: Attribute ] ) -> bool > CfgFolder for Context < ' a , F > {
34
+ impl < ' a > CfgFolder for StripUnconfigured < ' a > {
35
35
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 ) {
37
37
Some ( node)
38
38
} else {
39
39
None
@@ -43,7 +43,7 @@ impl<'a, F: FnMut(&[ast::Attribute]) -> bool> CfgFolder for Context<'a, F> {
43
43
fn visit_unconfigurable_expr ( & mut self , expr : & ast:: Expr ) {
44
44
if let Some ( attr) = expr. attrs ( ) . iter ( ) . find ( |a| is_cfg ( a) ) {
45
45
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) ;
47
47
}
48
48
}
49
49
}
@@ -58,16 +58,14 @@ pub fn strip_unconfigured_items(diagnostic: &Handler, krate: ast::Crate,
58
58
check_for_gated_stmt_expr_attributes ( & krate, feature_gated_cfgs) ;
59
59
60
60
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)
71
69
}
72
70
73
71
impl < T : CfgFolder > fold:: Folder for T {
@@ -158,17 +156,6 @@ impl<T: CfgFolder> fold::Folder for T {
158
156
}
159
157
}
160
158
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
-
172
159
fn fold_expr < F : CfgFolder > ( folder : & mut F , expr : P < ast:: Expr > ) -> P < ast:: Expr > {
173
160
expr. map ( |ast:: Expr { id, span, node, attrs} | {
174
161
fold:: noop_fold_expr ( ast:: Expr {
0 commit comments