@@ -79,16 +79,19 @@ struct MacroRulesMacroExpander {
79
79
}
80
80
81
81
impl TTMacroExpander for MacroRulesMacroExpander {
82
- fn expand < ' cx > ( & self ,
83
- cx : & ' cx mut ExtCtxt ,
84
- sp : Span ,
85
- input : TokenStream )
86
- -> Box < dyn MacResult +' cx > {
82
+ fn expand < ' cx > (
83
+ & self ,
84
+ cx : & ' cx mut ExtCtxt ,
85
+ sp : Span ,
86
+ input : TokenStream ,
87
+ def_span : Option < Span > ,
88
+ ) -> Box < dyn MacResult +' cx > {
87
89
if !self . valid {
88
90
return DummyResult :: any ( sp) ;
89
91
}
90
92
generic_extension ( cx,
91
93
sp,
94
+ def_span,
92
95
self . name ,
93
96
input,
94
97
& self . lhses ,
@@ -104,6 +107,7 @@ fn trace_macros_note(cx: &mut ExtCtxt, sp: Span, message: String) {
104
107
/// Given `lhses` and `rhses`, this is the new macro we create
105
108
fn generic_extension < ' cx > ( cx : & ' cx mut ExtCtxt ,
106
109
sp : Span ,
110
+ def_span : Option < Span > ,
107
111
name : ast:: Ident ,
108
112
arg : TokenStream ,
109
113
lhses : & [ quoted:: TokenTree ] ,
@@ -183,7 +187,14 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
183
187
}
184
188
185
189
let best_fail_msg = parse_failure_msg ( best_fail_tok. expect ( "ran no matchers" ) ) ;
186
- let mut err = cx. struct_span_err ( best_fail_spot. substitute_dummy ( sp) , & best_fail_msg) ;
190
+ let span = best_fail_spot. substitute_dummy ( sp) ;
191
+ let mut err = cx. struct_span_err ( span, & best_fail_msg) ;
192
+ err. span_label ( span, best_fail_msg) ;
193
+ if let Some ( sp) = def_span {
194
+ if cx. source_map ( ) . span_to_filename ( sp) . is_real ( ) && !sp. is_dummy ( ) {
195
+ err. span_label ( cx. source_map ( ) . def_span ( sp) , "when calling this macro" ) ;
196
+ }
197
+ }
187
198
188
199
// Check whether there's a missing comma in this macro call, like `println!("{}" a);`
189
200
if let Some ( ( arg, comma_span) ) = arg. add_comma ( ) {
@@ -194,7 +205,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
194
205
} ;
195
206
match TokenTree :: parse ( cx, lhs_tt, arg. clone ( ) ) {
196
207
Success ( _) => {
197
- if comma_span == DUMMY_SP {
208
+ if comma_span. is_dummy ( ) {
198
209
err. note ( "you might be missing a comma" ) ;
199
210
} else {
200
211
err. span_suggestion_short_with_applicability (
0 commit comments