@@ -14,9 +14,8 @@ use ast::{MacStmtStyle, Mrk, Stmt, StmtKind, ItemKind};
14
14
use ast:: TokenTree ;
15
15
use ast;
16
16
use ext:: mtwt;
17
- use ext:: build:: AstBuilder ;
18
17
use attr;
19
- use attr:: { AttrMetaMethods , WithAttrs , ThinAttributesExt } ;
18
+ use attr:: { AttrMetaMethods , ThinAttributesExt } ;
20
19
use codemap;
21
20
use codemap:: { Span , Spanned , ExpnInfo , ExpnId , NameAndSpan , MacroBang , MacroAttribute } ;
22
21
use config:: StripUnconfigured ;
@@ -87,19 +86,18 @@ impl MacroGenerable for Option<P<ast::Expr>> {
87
86
}
88
87
}
89
88
90
- pub fn expand_expr ( expr : ast:: Expr , fld : & mut MacroExpander ) -> P < ast:: Expr > {
89
+ pub fn expand_expr ( mut expr : ast:: Expr , fld : & mut MacroExpander ) -> P < ast:: Expr > {
91
90
match expr. node {
92
91
// expr_mac should really be expr_ext or something; it's the
93
92
// entry-point for all syntax extensions.
94
93
ast:: ExprKind :: Mac ( mac) => {
95
- expand_mac_invoc ( mac, None , expr. attrs . into_attr_vec ( ) , expr. span , fld)
94
+ return expand_mac_invoc ( mac, None , expr. attrs . into_attr_vec ( ) , expr. span , fld) ;
96
95
}
97
96
98
97
ast:: ExprKind :: While ( cond, body, opt_ident) => {
99
98
let cond = fld. fold_expr ( cond) ;
100
99
let ( body, opt_ident) = expand_loop_block ( body, opt_ident, fld) ;
101
- fld. cx . expr ( expr. span , ast:: ExprKind :: While ( cond, body, opt_ident) )
102
- . with_attrs ( fold_thin_attrs ( expr. attrs , fld) )
100
+ expr. node = ast:: ExprKind :: While ( cond, body, opt_ident) ;
103
101
}
104
102
105
103
ast:: ExprKind :: WhileLet ( pat, cond, body, opt_ident) => {
@@ -116,14 +114,12 @@ pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P<ast::Expr> {
116
114
} ) ;
117
115
assert ! ( rewritten_pats. len( ) == 1 ) ;
118
116
119
- let wl = ast:: ExprKind :: WhileLet ( rewritten_pats. remove ( 0 ) , cond, body, opt_ident) ;
120
- fld. cx . expr ( expr. span , wl) . with_attrs ( fold_thin_attrs ( expr. attrs , fld) )
117
+ expr. node = ast:: ExprKind :: WhileLet ( rewritten_pats. remove ( 0 ) , cond, body, opt_ident) ;
121
118
}
122
119
123
120
ast:: ExprKind :: Loop ( loop_block, opt_ident) => {
124
121
let ( loop_block, opt_ident) = expand_loop_block ( loop_block, opt_ident, fld) ;
125
- fld. cx . expr ( expr. span , ast:: ExprKind :: Loop ( loop_block, opt_ident) )
126
- . with_attrs ( fold_thin_attrs ( expr. attrs , fld) )
122
+ expr. node = ast:: ExprKind :: Loop ( loop_block, opt_ident) ;
127
123
}
128
124
129
125
ast:: ExprKind :: ForLoop ( pat, head, body, opt_ident) => {
@@ -140,8 +136,7 @@ pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P<ast::Expr> {
140
136
assert ! ( rewritten_pats. len( ) == 1 ) ;
141
137
142
138
let head = fld. fold_expr ( head) ;
143
- let fl = ast:: ExprKind :: ForLoop ( rewritten_pats. remove ( 0 ) , head, body, opt_ident) ;
144
- fld. cx . expr ( expr. span , fl) . with_attrs ( fold_thin_attrs ( expr. attrs , fld) )
139
+ expr. node = ast:: ExprKind :: ForLoop ( rewritten_pats. remove ( 0 ) , head, body, opt_ident) ;
145
140
}
146
141
147
142
ast:: ExprKind :: IfLet ( pat, sub_expr, body, else_opt) => {
@@ -159,25 +154,21 @@ pub fn expand_expr(expr: ast::Expr, fld: &mut MacroExpander) -> P<ast::Expr> {
159
154
160
155
let else_opt = else_opt. map ( |else_opt| fld. fold_expr ( else_opt) ) ;
161
156
let sub_expr = fld. fold_expr ( sub_expr) ;
162
- let il = ast:: ExprKind :: IfLet ( rewritten_pats. remove ( 0 ) , sub_expr, body, else_opt) ;
163
- fld. cx . expr ( expr. span , il) . with_attrs ( fold_thin_attrs ( expr. attrs , fld) )
157
+ expr. node = ast:: ExprKind :: IfLet ( rewritten_pats. remove ( 0 ) , sub_expr, body, else_opt) ;
164
158
}
165
159
166
160
ast:: ExprKind :: Closure ( capture_clause, fn_decl, block, fn_decl_span) => {
167
161
let ( rewritten_fn_decl, rewritten_block)
168
162
= expand_and_rename_fn_decl_and_block ( fn_decl, block, fld) ;
169
- let new_node = ast:: ExprKind :: Closure ( capture_clause,
170
- rewritten_fn_decl,
171
- rewritten_block,
172
- fn_decl_span) ;
173
- P ( ast:: Expr { id : expr. id ,
174
- node : new_node,
175
- span : expr. span ,
176
- attrs : fold_thin_attrs ( expr. attrs , fld) } )
163
+ expr. node = ast:: ExprKind :: Closure ( capture_clause,
164
+ rewritten_fn_decl,
165
+ rewritten_block,
166
+ fn_decl_span) ;
177
167
}
178
168
179
- _ => P ( noop_fold_expr ( expr, fld) ) ,
180
- }
169
+ _ => expr = noop_fold_expr ( expr, fld) ,
170
+ } ;
171
+ P ( expr)
181
172
}
182
173
183
174
/// Expand a macro invocation. Returns the result of expansion.
0 commit comments