@@ -19,7 +19,7 @@ use ext::build::AstBuilder;
1919use attr;
2020use attr:: AttrMetaMethods ;
2121use codemap;
22- use codemap:: { Span , Spanned , ExpnInfo , NameAndSpan , MacroBang , MacroAttribute } ;
22+ use codemap:: { Span , Spanned , ExpnInfo , NameAndSpan , MacroBang , MacroAttribute , CompilerExpansion } ;
2323use ext:: base:: * ;
2424use feature_gate:: { self , Features } ;
2525use fold;
@@ -34,6 +34,18 @@ use visit::Visitor;
3434use std_inject;
3535
3636pub 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+
3749 e. and_then ( |ast:: Expr { id, node, span} | match node {
3850 // expr_mac should really be expr_ext or something; it's the
3951 // entry-point for all syntax extensions.
@@ -77,6 +89,8 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
7789 // }
7890 // }
7991
92+ push_compiler_expansion ( fld, span, "while let expansion" ) ;
93+
8094 // `<pat> => <body>`
8195 let pat_arm = {
8296 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> {
98112 // `[opt_ident]: loop { ... }`
99113 let loop_block = fld. cx . block_expr ( match_expr) ;
100114 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
102118 }
103119
104120 // Desugar ExprIfLet
@@ -112,6 +128,8 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
112128 // _ => [<elseopt> | ()]
113129 // }
114130
131+ push_compiler_expansion ( fld, span, "if let expansion" ) ;
132+
115133 // `<pat> => <body>`
116134 let pat_arm = {
117135 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> {
173191 ast:: MatchSource :: IfLetDesugar {
174192 contains_else_clause : contains_else_clause,
175193 } ) ) ;
176- fld. fold_expr ( match_expr)
194+ let result = fld. fold_expr ( match_expr) ;
195+ fld. cx . bt_pop ( ) ;
196+ result
177197 }
178198
179199 // Desugar support for ExprIfLet in the ExprIf else position
180200 ast:: ExprIf ( cond, blk, elseopt) => {
181201 let elseopt = elseopt. map ( |els| els. and_then ( |els| match els. node {
182202 ast:: ExprIfLet ( ..) => {
203+ push_compiler_expansion ( fld, span, "if let expansion" ) ;
183204 // wrap the if-let expr in a block
184205 let span = els. span ;
185206 let blk = P ( ast:: Block {
@@ -189,7 +210,9 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
189210 rules : ast:: DefaultBlock ,
190211 span : span
191212 } ) ;
192- fld. cx . expr_block ( blk)
213+ let result = fld. cx . expr_block ( blk) ;
214+ fld. cx . bt_pop ( ) ;
215+ result
193216 }
194217 _ => P ( els)
195218 } ) ) ;
@@ -221,6 +244,10 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
221244 // result
222245 // }
223246
247+ push_compiler_expansion ( fld, span, "for loop expansion" ) ;
248+
249+ let span = fld. new_span ( span) ;
250+
224251 // expand <head>
225252 let head = fld. fold_expr ( head) ;
226253
@@ -235,10 +262,11 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
235262 rename_fld. fold_ident ( ident)
236263 } ;
237264
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>`
240267 let pat_arm = {
241268 let body_expr = fld. cx . expr_block ( body) ;
269+ let pat = noop_fold_pat ( pat, fld) ;
242270 let some_pat = fld. cx . pat_some ( pat_span, pat) ;
243271
244272 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> {
304332
305333 // `{ let result = ...; result }`
306334 let result_ident = token:: gensym_ident ( "result" ) ;
307- fld. cx . expr_block (
335+ let result = fld. cx . expr_block (
308336 fld. cx . block_all (
309337 span,
310338 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
312342 }
313343
314344 ast:: ExprClosure ( capture_clause, fn_decl, block) => {
345+ push_compiler_expansion ( fld, span, "closure expansion" ) ;
315346 let ( rewritten_fn_decl, rewritten_block)
316347 = expand_and_rename_fn_decl_and_block ( fn_decl, block, fld) ;
317348 let new_node = ast:: ExprClosure ( capture_clause,
318349 rewritten_fn_decl,
319350 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
321354 }
322355
323356 _ => {
0 commit comments