@@ -84,6 +84,12 @@ impl TTMacroExpander for MacroRulesMacroExpander {
84
84
}
85
85
}
86
86
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
+
87
93
/// Given `lhses` and `rhses`, this is the new macro we create
88
94
fn generic_extension < ' cx > ( cx : & ' cx mut ExtCtxt ,
89
95
sp : Span ,
@@ -93,9 +99,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
93
99
rhses : & [ quoted:: TokenTree ] )
94
100
-> Box < MacResult +' cx > {
95
101
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) ) ;
99
103
}
100
104
101
105
// Which arm's failure should we report? (the one furthest along)
@@ -117,6 +121,11 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
117
121
} ;
118
122
// rhs has holes ( `$id` and `$(...)` that need filled)
119
123
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
+
120
129
let directory = Directory {
121
130
path : cx. current_expansion . module . directory . clone ( ) ,
122
131
ownership : cx. current_expansion . directory_ownership ,
0 commit comments