@@ -84,6 +84,12 @@ impl TTMacroExpander for MacroRulesMacroExpander {
8484 }
8585}
8686
87+ fn trace_macros_note ( cx : & mut ExtCtxt , sp : Span , message : String ) {
88+ let sp = sp. macro_backtrace ( ) . last ( ) . map ( |trace| trace. call_site ) . unwrap_or ( sp) ;
89+ let mut values: & mut Vec < String > = cx. expansions . entry ( sp) . or_insert_with ( Vec :: new) ;
90+ values. push ( message) ;
91+ }
92+
8793/// Given `lhses` and `rhses`, this is the new macro we create
8894fn generic_extension < ' cx > ( cx : & ' cx mut ExtCtxt ,
8995 sp : Span ,
@@ -93,9 +99,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
9399 rhses : & [ quoted:: TokenTree ] )
94100 -> Box < MacResult +' cx > {
95101 if cx. trace_macros ( ) {
96- let sp = sp. macro_backtrace ( ) . last ( ) . map ( |trace| trace. call_site ) . unwrap_or ( sp) ;
97- let mut values: & mut Vec < String > = cx. expansions . entry ( sp) . or_insert_with ( Vec :: new) ;
98- values. push ( format ! ( "expands to `{}! {{ {} }}`" , name, arg) ) ;
102+ trace_macros_note ( cx, sp, format ! ( "expanding `{}! {{ {} }}`" , name, arg) ) ;
99103 }
100104
101105 // Which arm's failure should we report? (the one furthest along)
@@ -117,6 +121,11 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
117121 } ;
118122 // rhs has holes ( `$id` and `$(...)` that need filled)
119123 let tts = transcribe ( & cx. parse_sess . span_diagnostic , Some ( named_matches) , rhs) ;
124+
125+ if cx. trace_macros ( ) {
126+ trace_macros_note ( cx, sp, format ! ( "to `{}`" , tts) ) ;
127+ }
128+
120129 let directory = Directory {
121130 path : cx. current_expansion . module . directory . clone ( ) ,
122131 ownership : cx. current_expansion . directory_ownership ,
0 commit comments