|
11 | 11 |
|
12 | 12 | use syntax::fold::ast_fold;
|
13 | 13 | use syntax::{ast, fold, attr};
|
| 14 | +use syntax::codemap; |
14 | 15 |
|
15 | 16 | struct Context<'a> {
|
16 | 17 | in_cfg: 'a |attrs: &[ast::Attribute]| -> bool,
|
@@ -109,12 +110,47 @@ fn fold_item_underscore(cx: &Context, item: &ast::item_) -> ast::item_ {
|
109 | 110 | .collect();
|
110 | 111 | ast::item_trait((*a).clone(), (*b).clone(), methods)
|
111 | 112 | }
|
112 |
| - ref item => (*item).clone(), |
| 113 | + ast::item_struct(def, ref generics) => { |
| 114 | + ast::item_struct(fold_struct(cx, def), generics.clone()) |
| 115 | + } |
| 116 | + ast::item_enum(ref def, ref generics) => { |
| 117 | + let mut variants = def.variants.iter().map(|c| c.clone()).filter(|m| { |
| 118 | + (cx.in_cfg)(m.node.attrs) |
| 119 | + }).map(|v| { |
| 120 | + match v.node.kind { |
| 121 | + ast::tuple_variant_kind(..) => v, |
| 122 | + ast::struct_variant_kind(def) => { |
| 123 | + let def = fold_struct(cx, def); |
| 124 | + @codemap::Spanned { |
| 125 | + node: ast::variant_ { |
| 126 | + kind: ast::struct_variant_kind(def), |
| 127 | + ..v.node.clone() |
| 128 | + }, |
| 129 | + ..*v |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + }); |
| 134 | + ast::item_enum(ast::enum_def { |
| 135 | + variants: variants.collect(), |
| 136 | + }, generics.clone()) |
| 137 | + } |
| 138 | + ref item => item.clone(), |
113 | 139 | };
|
114 | 140 |
|
115 | 141 | fold::noop_fold_item_underscore(&item, cx)
|
116 | 142 | }
|
117 | 143 |
|
| 144 | +fn fold_struct(cx: &Context, def: &ast::struct_def) -> @ast::struct_def { |
| 145 | + let mut fields = def.fields.iter().map(|c| c.clone()).filter(|m| { |
| 146 | + (cx.in_cfg)(m.node.attrs) |
| 147 | + }); |
| 148 | + @ast::struct_def { |
| 149 | + fields: fields.collect(), |
| 150 | + ctor_id: def.ctor_id, |
| 151 | + } |
| 152 | +} |
| 153 | + |
118 | 154 | fn retain_stmt(cx: &Context, stmt: @ast::Stmt) -> bool {
|
119 | 155 | match stmt.node {
|
120 | 156 | ast::StmtDecl(decl, _) => {
|
|
0 commit comments