@@ -79,16 +79,19 @@ struct MacroRulesMacroExpander {
7979}
8080
8181impl 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 > {
8789 if !self . valid {
8890 return DummyResult :: any ( sp) ;
8991 }
9092 generic_extension ( cx,
9193 sp,
94+ def_span,
9295 self . name ,
9396 input,
9497 & self . lhses ,
@@ -104,6 +107,7 @@ fn trace_macros_note(cx: &mut ExtCtxt, sp: Span, message: String) {
104107/// Given `lhses` and `rhses`, this is the new macro we create
105108fn generic_extension < ' cx > ( cx : & ' cx mut ExtCtxt ,
106109 sp : Span ,
110+ def_span : Option < Span > ,
107111 name : ast:: Ident ,
108112 arg : TokenStream ,
109113 lhses : & [ quoted:: TokenTree ] ,
@@ -183,7 +187,14 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
183187 }
184188
185189 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+ }
187198
188199 // Check whether there's a missing comma in this macro call, like `println!("{}" a);`
189200 if let Some ( ( arg, comma_span) ) = arg. add_comma ( ) {
@@ -194,7 +205,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
194205 } ;
195206 match TokenTree :: parse ( cx, lhs_tt, arg. clone ( ) ) {
196207 Success ( _) => {
197- if comma_span == DUMMY_SP {
208+ if comma_span. is_dummy ( ) {
198209 err. note ( "you might be missing a comma" ) ;
199210 } else {
200211 err. span_suggestion_short_with_applicability (
0 commit comments