@@ -53,20 +53,24 @@ impl<'a> ParserAnyMacro<'a> {
53
53
pub fn make ( mut self : Box < ParserAnyMacro < ' a > > , kind : AstFragmentKind ) -> AstFragment {
54
54
let ParserAnyMacro { site_span, macro_ident, ref mut parser, arm_span } = * self ;
55
55
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
+ }
64
60
let msg = & e. message[ 0 ] ;
65
61
e. message[ 0 ] = (
66
62
msg. 0 . replace( ", found `<eof>`" , ", found the end of the macro arm" ) ,
67
63
msg. 1 ,
68
64
) ;
69
65
}
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
+ }
70
74
e
71
75
} ) ) ;
72
76
0 commit comments