@@ -81,20 +81,10 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
8181 // be the root of the call stack. That's the most
8282 // relevant span and it's the actual invocation of
8383 // the macro.
84- let mut relevant_info = cx. backtrace ( ) ;
85- let mut einfo = relevant_info. unwrap ( ) ;
86- loop {
87- match relevant_info {
88- None => { break }
89- Some ( e) => {
90- einfo = e;
91- relevant_info = einfo. call_site . expn_info ;
92- }
93- }
94- }
84+ let mac_span = original_span ( cx) ;
9585
9686 let expanded =
97- match expandfun ( cx, einfo . call_site ,
87+ match expandfun ( cx, mac_span . call_site ,
9888 marked_before, marked_ctxt) {
9989 MRExpr ( e) => e,
10090 MRAny ( expr_maker, _, _) => expr_maker ( ) ,
@@ -400,11 +390,11 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
400390 -> ( Option < Stmt_ > , Span ) {
401391 // why the copying here and not in expand_expr?
402392 // looks like classic changed-in-only-one-place
403- let ( mac , pth, tts, semi, ctxt) = match * s {
393+ let ( pth, tts, semi, ctxt) = match * s {
404394 StmtMac ( ref mac, semi) => {
405395 match mac. node {
406396 mac_invoc_tt( ref pth, ref tts, ctxt) => {
407- ( ( * mac ) . clone ( ) , pth, ( * tts) . clone ( ) , semi, ctxt)
397+ ( pth, ( * tts) . clone ( ) , semi, ctxt)
408398 }
409399 }
410400 }
@@ -431,7 +421,13 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
431421 // mark before expansion:
432422 let marked_tts = mark_tts ( tts, fm) ;
433423 let marked_ctxt = new_mark ( fm, ctxt) ;
434- let expanded = match expandfun ( cx, mac. span , marked_tts, marked_ctxt) {
424+
425+ // See the comment in expand_expr for why we want the original span,
426+ // not the current mac.span.
427+ let mac_span = original_span ( cx) ;
428+
429+ let expanded = match expandfun ( cx, mac_span. call_site ,
430+ marked_tts, marked_ctxt) {
435431 MRExpr ( e) =>
436432 @codemap:: Spanned { node : StmtExpr ( e, ast:: DUMMY_NODE_ID ) ,
437433 span : e. span } ,
@@ -1270,6 +1266,20 @@ pub fn mtwt_cancel_outer_mark(tts: &[ast::token_tree], ctxt: ast::SyntaxContext)
12701266 mark_tts ( tts, outer_mark)
12711267}
12721268
1269+ fn original_span ( cx : @ExtCtxt ) -> @codemap:: ExpnInfo {
1270+ let mut relevant_info = cx. backtrace ( ) ;
1271+ let mut einfo = relevant_info. unwrap ( ) ;
1272+ loop {
1273+ match relevant_info {
1274+ None => { break }
1275+ Some ( e) => {
1276+ einfo = e;
1277+ relevant_info = einfo. call_site . expn_info ;
1278+ }
1279+ }
1280+ }
1281+ return einfo;
1282+ }
12731283
12741284#[ cfg( test) ]
12751285mod test {
0 commit comments