@@ -81,20 +81,10 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
81
81
// be the root of the call stack. That's the most
82
82
// relevant span and it's the actual invocation of
83
83
// 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) ;
95
85
96
86
let expanded =
97
- match expandfun ( cx, einfo . call_site ,
87
+ match expandfun ( cx, mac_span . call_site ,
98
88
marked_before, marked_ctxt) {
99
89
MRExpr ( e) => e,
100
90
MRAny ( expr_maker, _, _) => expr_maker ( ) ,
@@ -400,11 +390,11 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
400
390
-> ( Option < Stmt_ > , Span ) {
401
391
// why the copying here and not in expand_expr?
402
392
// 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 {
404
394
StmtMac ( ref mac, semi) => {
405
395
match mac. node {
406
396
mac_invoc_tt( ref pth, ref tts, ctxt) => {
407
- ( ( * mac ) . clone ( ) , pth, ( * tts) . clone ( ) , semi, ctxt)
397
+ ( pth, ( * tts) . clone ( ) , semi, ctxt)
408
398
}
409
399
}
410
400
}
@@ -431,7 +421,13 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
431
421
// mark before expansion:
432
422
let marked_tts = mark_tts ( tts, fm) ;
433
423
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) {
435
431
MRExpr ( e) =>
436
432
@codemap:: Spanned { node : StmtExpr ( e, ast:: DUMMY_NODE_ID ) ,
437
433
span : e. span } ,
@@ -1270,6 +1266,20 @@ pub fn mtwt_cancel_outer_mark(tts: &[ast::token_tree], ctxt: ast::SyntaxContext)
1270
1266
mark_tts ( tts, outer_mark)
1271
1267
}
1272
1268
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
+ }
1273
1283
1274
1284
#[ cfg( test) ]
1275
1285
mod test {
0 commit comments