@@ -19,7 +19,7 @@ use ext::build::AstBuilder;
19
19
use attr;
20
20
use attr:: AttrMetaMethods ;
21
21
use codemap;
22
- use codemap:: { Span , Spanned , ExpnInfo , NameAndSpan , MacroBang , MacroAttribute } ;
22
+ use codemap:: { Span , Spanned , ExpnInfo , NameAndSpan , MacroBang , MacroAttribute , CompilerExpansion } ;
23
23
use ext:: base:: * ;
24
24
use feature_gate:: { self , Features } ;
25
25
use fold;
@@ -34,6 +34,18 @@ use visit::Visitor;
34
34
use std_inject;
35
35
36
36
pub fn expand_expr ( e : P < ast:: Expr > , fld : & mut MacroExpander ) -> P < ast:: Expr > {
37
+ fn push_compiler_expansion ( fld : & mut MacroExpander , span : Span , expansion_desc : & str ) {
38
+ fld. cx . bt_push ( ExpnInfo {
39
+ call_site : span,
40
+ callee : NameAndSpan {
41
+ name : expansion_desc. to_string ( ) ,
42
+ format : CompilerExpansion ,
43
+ allow_internal_unstable : true ,
44
+ span : None ,
45
+ } ,
46
+ } ) ;
47
+ }
48
+
37
49
e. and_then ( |ast:: Expr { id, node, span} | match node {
38
50
// expr_mac should really be expr_ext or something; it's the
39
51
// entry-point for all syntax extensions.
@@ -77,6 +89,8 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
77
89
// }
78
90
// }
79
91
92
+ push_compiler_expansion ( fld, span, "while let expansion" ) ;
93
+
80
94
// `<pat> => <body>`
81
95
let pat_arm = {
82
96
let body_expr = fld. cx . expr_block ( body) ;
@@ -98,7 +112,9 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
98
112
// `[opt_ident]: loop { ... }`
99
113
let loop_block = fld. cx . block_expr ( match_expr) ;
100
114
let ( loop_block, opt_ident) = expand_loop_block ( loop_block, opt_ident, fld) ;
101
- fld. cx . expr ( span, ast:: ExprLoop ( loop_block, opt_ident) )
115
+ let result = fld. cx . expr ( span, ast:: ExprLoop ( loop_block, opt_ident) ) ;
116
+ fld. cx . bt_pop ( ) ;
117
+ result
102
118
}
103
119
104
120
// Desugar ExprIfLet
@@ -112,6 +128,8 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
112
128
// _ => [<elseopt> | ()]
113
129
// }
114
130
131
+ push_compiler_expansion ( fld, span, "if let expansion" ) ;
132
+
115
133
// `<pat> => <body>`
116
134
let pat_arm = {
117
135
let body_expr = fld. cx . expr_block ( body) ;
@@ -173,13 +191,16 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
173
191
ast:: MatchSource :: IfLetDesugar {
174
192
contains_else_clause : contains_else_clause,
175
193
} ) ) ;
176
- fld. fold_expr ( match_expr)
194
+ let result = fld. fold_expr ( match_expr) ;
195
+ fld. cx . bt_pop ( ) ;
196
+ result
177
197
}
178
198
179
199
// Desugar support for ExprIfLet in the ExprIf else position
180
200
ast:: ExprIf ( cond, blk, elseopt) => {
181
201
let elseopt = elseopt. map ( |els| els. and_then ( |els| match els. node {
182
202
ast:: ExprIfLet ( ..) => {
203
+ push_compiler_expansion ( fld, span, "if let expansion" ) ;
183
204
// wrap the if-let expr in a block
184
205
let span = els. span ;
185
206
let blk = P ( ast:: Block {
@@ -189,7 +210,9 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
189
210
rules : ast:: DefaultBlock ,
190
211
span : span
191
212
} ) ;
192
- fld. cx . expr_block ( blk)
213
+ let result = fld. cx . expr_block ( blk) ;
214
+ fld. cx . bt_pop ( ) ;
215
+ result
193
216
}
194
217
_ => P ( els)
195
218
} ) ) ;
@@ -221,6 +244,10 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
221
244
// result
222
245
// }
223
246
247
+ push_compiler_expansion ( fld, span, "for loop expansion" ) ;
248
+
249
+ let span = fld. new_span ( span) ;
250
+
224
251
// expand <head>
225
252
let head = fld. fold_expr ( head) ;
226
253
@@ -235,10 +262,11 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
235
262
rename_fld. fold_ident ( ident)
236
263
} ;
237
264
238
- let pat_span = pat. span ;
239
- // `:; std::option::Option::Some(<pat>) => <body>`
265
+ let pat_span = fld . new_span ( pat. span ) ;
266
+ // `:: std::option::Option::Some(<pat>) => <body>`
240
267
let pat_arm = {
241
268
let body_expr = fld. cx . expr_block ( body) ;
269
+ let pat = noop_fold_pat ( pat, fld) ;
242
270
let some_pat = fld. cx . pat_some ( pat_span, pat) ;
243
271
244
272
fld. cx . arm ( pat_span, vec ! [ some_pat] , body_expr)
@@ -304,20 +332,25 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
304
332
305
333
// `{ let result = ...; result }`
306
334
let result_ident = token:: gensym_ident ( "result" ) ;
307
- fld. cx . expr_block (
335
+ let result = fld. cx . expr_block (
308
336
fld. cx . block_all (
309
337
span,
310
338
vec ! [ fld. cx. stmt_let( span, false , result_ident, match_expr) ] ,
311
- Some ( fld. cx . expr_ident ( span, result_ident) ) ) )
339
+ Some ( fld. cx . expr_ident ( span, result_ident) ) ) ) ;
340
+ fld. cx . bt_pop ( ) ;
341
+ result
312
342
}
313
343
314
344
ast:: ExprClosure ( capture_clause, fn_decl, block) => {
345
+ push_compiler_expansion ( fld, span, "closure expansion" ) ;
315
346
let ( rewritten_fn_decl, rewritten_block)
316
347
= expand_and_rename_fn_decl_and_block ( fn_decl, block, fld) ;
317
348
let new_node = ast:: ExprClosure ( capture_clause,
318
349
rewritten_fn_decl,
319
350
rewritten_block) ;
320
- P ( ast:: Expr { id : id, node : new_node, span : fld. new_span ( span) } )
351
+ let result = P ( ast:: Expr { id : id, node : new_node, span : fld. new_span ( span) } ) ;
352
+ fld. cx . bt_pop ( ) ;
353
+ result
321
354
}
322
355
323
356
_ => {
0 commit comments