@@ -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 } ,
@@ -715,11 +711,11 @@ pub fn std_macros() -> @str {
715711 }
716712 } )
717713 )
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) * ) }
723719 ) )
724720
725721 macro_rules! log2(
@@ -730,11 +726,11 @@ pub fn std_macros() -> @str {
730726 }
731727 } )
732728 )
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) * ) }
738734 ) )
739735
740736 macro_rules! fail(
@@ -753,8 +749,8 @@ pub fn std_macros() -> @str {
753749 ( ) => (
754750 fail!( \" explicit failure\" )
755751 ) ;
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!( ) )
758754 )
759755 )
760756
@@ -958,17 +954,25 @@ pub fn std_macros() -> @str {
958954 )
959955 )
960956
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+ ) )
961966 // FIXME(#6846) once stdio is redesigned, this shouldn't perform an
962967 // allocation but should rather delegate to an invocation of
963968 // write! instead of format!
964969 macro_rules! print (
965- ( $( $arg: tt) + ) => ( :: std:: io:: print( format!( $( $arg) + ) ) )
970+ ( $( $arg: tt) * ) => ( :: std:: io:: print( format!( $( $arg) * ) ) )
966971 )
967-
968972 // FIXME(#6846) once stdio is redesigned, this shouldn't perform an
969973 // allocation but should rather delegate to an io::Writer
970974 macro_rules! println (
971- ( $( $arg: tt) + ) => ( :: std:: io:: println( format!( $( $arg) + ) ) )
975+ ( $( $arg: tt) * ) => ( :: std:: io:: println( format!( $( $arg) * ) ) )
972976 )
973977
974978 // 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)
12621266 mark_tts ( tts, outer_mark)
12631267}
12641268
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+ }
12651283
12661284#[ cfg( test) ]
12671285mod test {
0 commit comments