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