@@ -74,16 +74,19 @@ struct MacroRulesMacroExpander {
7474}
7575
7676impl 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 > {
8284 if !self . valid {
8385 return DummyResult :: any ( sp) ;
8486 }
8587 generic_extension ( cx,
8688 sp,
89+ def_span,
8790 self . name ,
8891 input,
8992 & self . lhses ,
@@ -99,6 +102,7 @@ fn trace_macros_note(cx: &mut ExtCtxt, sp: Span, message: String) {
99102/// Given `lhses` and `rhses`, this is the new macro we create
100103fn generic_extension < ' cx > ( cx : & ' cx mut ExtCtxt ,
101104 sp : Span ,
105+ def_span : Option < Span > ,
102106 name : ast:: Ident ,
103107 arg : TokenStream ,
104108 lhses : & [ quoted:: TokenTree ] ,
@@ -178,7 +182,14 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
178182 }
179183
180184 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+ }
182193
183194 // Check whether there's a missing comma in this macro call, like `println!("{}" a);`
184195 if let Some ( ( arg, comma_span) ) = arg. add_comma ( ) {
@@ -189,7 +200,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
189200 } ;
190201 match TokenTree :: parse ( cx, lhs_tt, arg. clone ( ) ) {
191202 Success ( _) => {
192- if comma_span == DUMMY_SP {
203+ if comma_span. is_dummy ( ) {
193204 err. note ( "you might be missing a comma" ) ;
194205 } else {
195206 err. span_suggestion_short_with_applicability (
0 commit comments