@@ -53,20 +53,24 @@ impl<'a> ParserAnyMacro<'a> {
5353 pub fn make ( mut self : Box < ParserAnyMacro < ' a > > , kind : AstFragmentKind ) -> AstFragment {
5454 let ParserAnyMacro { site_span, macro_ident, ref mut parser, arm_span } = * self ;
5555 let fragment = panictry ! ( parser. parse_ast_fragment( kind, true ) . map_err( |mut e| {
56- if e. span. is_dummy( ) { // Get around lack of span in error (#30128)
57- e. set_span( site_span) ;
58- e. span_label( site_span, "in this macro expansion" ) ;
59- e. span_label( arm_span, "in this macro arm" ) ;
60- } else if parser. token == token:: Eof { // (#52866)
61- e. set_span( parser. sess. source_map( ) . next_point( parser. span) ) ;
62- }
63- if parser. token == token:: Eof {
56+ if parser. token == token:: Eof && e. message( ) . ends_with( ", found `<eof>`" ) {
57+ if !e. span. is_dummy( ) { // early end of macro arm (#52866)
58+ e. replace_span_with( parser. sess. source_map( ) . next_point( parser. span) ) ;
59+ }
6460 let msg = & e. message[ 0 ] ;
6561 e. message[ 0 ] = (
6662 msg. 0 . replace( ", found `<eof>`" , ", found the end of the macro arm" ) ,
6763 msg. 1 ,
6864 ) ;
6965 }
66+ if e. span. is_dummy( ) { // Get around lack of span in error (#30128)
67+ e. replace_span_with( site_span) ;
68+ if parser. sess. source_map( ) . span_to_filename( arm_span) . is_real( ) {
69+ e. span_label( arm_span, "in this macro arm" ) ;
70+ }
71+ } else if !parser. sess. source_map( ) . span_to_filename( parser. span) . is_real( ) {
72+ e. span_label( site_span, "in this macro invocation" ) ;
73+ }
7074 e
7175 } ) ) ;
7276
0 commit comments