Skip to content

Commit 0608b1d

Browse files
committed
Fixed macro expander not folding attributes (though I'm not sure if that is actually neccessary)
1 parent f0beba0 commit 0608b1d

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/libsyntax/ext/expand.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ use std::collections::HashSet;
3737

3838
pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
3939
let expr_span = e.span;
40-
// FIXME: Drop attrs on the floor for now.
4140
return e.and_then(|ast::Expr {id, node, span, attrs}| match node {
4241

4342
// expr_mac should really be expr_ext or something; it's the
4443
// entry-point for all syntax extensions.
4544
ast::ExprMac(mac) => {
4645

47-
// drop attributes on the macro itself
48-
let _ = attrs;
46+
// FIXME: for now, drop attributes on the macro itself
47+
drop(attrs);
4948

5049
let expanded_expr = match expand_mac_invoc(mac, span,
5150
|r| r.make_expr(),
@@ -79,14 +78,14 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
7978
let placer = fld.fold_expr(placer);
8079
let value_expr = fld.fold_expr(value_expr);
8180
fld.cx.expr(span, ast::ExprInPlace(placer, value_expr))
82-
.with_attrs(attrs)
81+
.with_attrs(fold_thin_attrs(attrs, fld))
8382
}
8483

8584
ast::ExprWhile(cond, body, opt_ident) => {
8685
let cond = fld.fold_expr(cond);
8786
let (body, opt_ident) = expand_loop_block(body, opt_ident, fld);
8887
fld.cx.expr(span, ast::ExprWhile(cond, body, opt_ident))
89-
.with_attrs(attrs)
88+
.with_attrs(fold_thin_attrs(attrs, fld))
9089
}
9190

9291
ast::ExprWhileLet(pat, expr, body, opt_ident) => {
@@ -104,13 +103,13 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
104103
assert!(rewritten_pats.len() == 1);
105104

106105
fld.cx.expr(span, ast::ExprWhileLet(rewritten_pats.remove(0), expr, body, opt_ident))
107-
.with_attrs(attrs)
106+
.with_attrs(fold_thin_attrs(attrs, fld))
108107
}
109108

110109
ast::ExprLoop(loop_block, opt_ident) => {
111110
let (loop_block, opt_ident) = expand_loop_block(loop_block, opt_ident, fld);
112111
fld.cx.expr(span, ast::ExprLoop(loop_block, opt_ident))
113-
.with_attrs(attrs)
112+
.with_attrs(fold_thin_attrs(attrs, fld))
114113
}
115114

116115
ast::ExprForLoop(pat, head, body, opt_ident) => {
@@ -128,7 +127,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
128127

129128
let head = fld.fold_expr(head);
130129
fld.cx.expr(span, ast::ExprForLoop(rewritten_pats.remove(0), head, body, opt_ident))
131-
.with_attrs(attrs)
130+
.with_attrs(fold_thin_attrs(attrs, fld))
132131
}
133132

134133
ast::ExprIfLet(pat, sub_expr, body, else_opt) => {
@@ -147,7 +146,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
147146
let else_opt = else_opt.map(|else_opt| fld.fold_expr(else_opt));
148147
let sub_expr = fld.fold_expr(sub_expr);
149148
fld.cx.expr(span, ast::ExprIfLet(rewritten_pats.remove(0), sub_expr, body, else_opt))
150-
.with_attrs(attrs)
149+
.with_attrs(fold_thin_attrs(attrs, fld))
151150
}
152151

153152
ast::ExprClosure(capture_clause, fn_decl, block) => {
@@ -157,17 +156,16 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
157156
rewritten_fn_decl,
158157
rewritten_block);
159158
P(ast::Expr{id:id, node: new_node, span: fld.new_span(span),
160-
attrs: None})
161-
.with_attrs(attrs)
159+
attrs: fold_thin_attrs(attrs, fld)})
162160
}
163161

164162
_ => {
165163
P(noop_fold_expr(ast::Expr {
166164
id: id,
167165
node: node,
168166
span: span,
169-
attrs: None
170-
}, fld)).with_attrs(attrs)
167+
attrs: attrs
168+
}, fld))
171169
}
172170
});
173171
}
@@ -506,8 +504,8 @@ fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
506504
_ => return expand_non_macro_stmt(stmt, fld)
507505
};
508506

509-
// FIXME: drop attrs for macros.
510-
let _ = attrs;
507+
// FIXME: for now, drop attrs on macros.
508+
drop(attrs);
511509

512510
let maybe_new_items =
513511
expand_mac_invoc(mac.and_then(|m| m), stmt.span,

src/libsyntax/fold.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
use ast::*;
2222
use ast;
23-
use attr::ThinAttributesExt;
23+
use attr::{ThinAttributes, ThinAttributesExt};
2424
use ast_util;
2525
use codemap::{respan, Span, Spanned};
2626
use owned_slice::OwnedSlice;
@@ -365,6 +365,10 @@ pub fn fold_attrs<T: Folder>(attrs: Vec<Attribute>, fld: &mut T) -> Vec<Attribut
365365
attrs.into_iter().flat_map(|x| fld.fold_attribute(x)).collect()
366366
}
367367

368+
pub fn fold_thin_attrs<T: Folder>(attrs: ThinAttributes, fld: &mut T) -> ThinAttributes {
369+
attrs.map_thin_attrs(|v| fold_attrs(v, fld))
370+
}
371+
368372
pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body}: Arm, fld: &mut T) -> Arm {
369373
Arm {
370374
attrs: fold_attrs(attrs, fld),

0 commit comments

Comments
 (0)