@@ -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 } ,
@@ -715,11 +711,11 @@ pub fn std_macros() -> @str {
715
711
}
716
712
} )
717
713
)
718
- macro_rules! error( ( $( $arg: tt) + ) => ( log!( 1u32 , $( $arg) + ) ) )
719
- macro_rules! warn ( ( $( $arg: tt) + ) => ( log!( 2u32 , $( $arg) + ) ) )
720
- macro_rules! info ( ( $( $arg: tt) + ) => ( log!( 3u32 , $( $arg) + ) ) )
721
- macro_rules! debug( ( $( $arg: tt) + ) => (
722
- if cfg!( debug) { log!( 4u32 , $( $arg) + ) }
714
+ macro_rules! error( ( $( $arg: tt) * ) => ( log!( 1u32 , $( $arg) * ) ) )
715
+ macro_rules! warn ( ( $( $arg: tt) * ) => ( log!( 2u32 , $( $arg) * ) ) )
716
+ macro_rules! info ( ( $( $arg: tt) * ) => ( log!( 3u32 , $( $arg) * ) ) )
717
+ macro_rules! debug( ( $( $arg: tt) * ) => (
718
+ if cfg!( debug) { log!( 4u32 , $( $arg) * ) }
723
719
) )
724
720
725
721
macro_rules! log2(
@@ -730,11 +726,11 @@ pub fn std_macros() -> @str {
730
726
}
731
727
} )
732
728
)
733
- macro_rules! error2( ( $( $arg: tt) + ) => ( log2!( 1u32 , $( $arg) + ) ) )
734
- macro_rules! warn2 ( ( $( $arg: tt) + ) => ( log2!( 2u32 , $( $arg) + ) ) )
735
- macro_rules! info2 ( ( $( $arg: tt) + ) => ( log2!( 3u32 , $( $arg) + ) ) )
736
- macro_rules! debug2( ( $( $arg: tt) + ) => (
737
- if cfg!( debug) { log2!( 4u32 , $( $arg) + ) }
729
+ macro_rules! error2( ( $( $arg: tt) * ) => ( log2!( 1u32 , $( $arg) * ) ) )
730
+ macro_rules! warn2 ( ( $( $arg: tt) * ) => ( log2!( 2u32 , $( $arg) * ) ) )
731
+ macro_rules! info2 ( ( $( $arg: tt) * ) => ( log2!( 3u32 , $( $arg) * ) ) )
732
+ macro_rules! debug2( ( $( $arg: tt) * ) => (
733
+ if cfg!( debug) { log2!( 4u32 , $( $arg) * ) }
738
734
) )
739
735
740
736
macro_rules! fail(
@@ -753,8 +749,8 @@ pub fn std_macros() -> @str {
753
749
( ) => (
754
750
fail!( \" explicit failure\" )
755
751
) ;
756
- ( $( $arg: tt) + ) => (
757
- :: std:: sys:: FailWithCause :: fail_with( format!( $( $arg) + ) , file!( ) , line!( ) )
752
+ ( $( $arg: tt) * ) => (
753
+ :: std:: sys:: FailWithCause :: fail_with( format!( $( $arg) * ) , file!( ) , line!( ) )
758
754
)
759
755
)
760
756
@@ -958,17 +954,25 @@ pub fn std_macros() -> @str {
958
954
)
959
955
)
960
956
957
+ macro_rules! format( ( $( $arg: tt) * ) => (
958
+ format_args!( :: std:: fmt:: format, $( $arg) * )
959
+ ) )
960
+ macro_rules! write( ( $dst: expr, $( $arg: tt) * ) => (
961
+ format_args!( |args| { :: std:: fmt:: write( $dst, args) } , $( $arg) * )
962
+ ) )
963
+ macro_rules! writeln( ( $dst: expr, $( $arg: tt) * ) => (
964
+ format_args!( |args| { :: std:: fmt:: writeln( $dst, args) } , $( $arg) * )
965
+ ) )
961
966
// FIXME(#6846) once stdio is redesigned, this shouldn't perform an
962
967
// allocation but should rather delegate to an invocation of
963
968
// write! instead of format!
964
969
macro_rules! print (
965
- ( $( $arg: tt) + ) => ( :: std:: io:: print( format!( $( $arg) + ) ) )
970
+ ( $( $arg: tt) * ) => ( :: std:: io:: print( format!( $( $arg) * ) ) )
966
971
)
967
-
968
972
// FIXME(#6846) once stdio is redesigned, this shouldn't perform an
969
973
// allocation but should rather delegate to an io::Writer
970
974
macro_rules! println (
971
- ( $( $arg: tt) + ) => ( :: std:: io:: println( format!( $( $arg) + ) ) )
975
+ ( $( $arg: tt) * ) => ( :: std:: io:: println( format!( $( $arg) * ) ) )
972
976
)
973
977
974
978
// NOTE: use this after a snapshot lands to abstract the details
@@ -1262,6 +1266,20 @@ pub fn mtwt_cancel_outer_mark(tts: &[ast::token_tree], ctxt: ast::SyntaxContext)
1262
1266
mark_tts ( tts, outer_mark)
1263
1267
}
1264
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
+ }
1265
1283
1266
1284
#[ cfg( test) ]
1267
1285
mod test {
0 commit comments