From c45871ba02430c3af6453d5636f8ad0afb7eb35f Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Mon, 5 Nov 2018 16:27:28 -0800 Subject: Keep label on moved spans and point at macro invocation on parse error --- src/libsyntax/ext/tt/macro_rules.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index fa10d219ad6..9f3a80b1151 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -53,20 +53,24 @@ impl<'a> ParserAnyMacro<'a> { pub fn make(mut self: Box>, kind: AstFragmentKind) -> AstFragment { let ParserAnyMacro { site_span, macro_ident, ref mut parser, arm_span } = *self; let fragment = panictry!(parser.parse_ast_fragment(kind, true).map_err(|mut e| { - if e.span.is_dummy() { // Get around lack of span in error (#30128) - e.set_span(site_span); - e.span_label(site_span, "in this macro expansion"); - e.span_label(arm_span, "in this macro arm"); - } else if parser.token == token::Eof { // (#52866) - e.set_span(parser.sess.source_map().next_point(parser.span)); - } - if parser.token == token::Eof { + if parser.token == token::Eof && e.message().ends_with(", found ``") { + if !e.span.is_dummy() { // early end of macro arm (#52866) + e.replace_span_with(parser.sess.source_map().next_point(parser.span)); + } let msg = &e.message[0]; e.message[0] = ( msg.0.replace(", found ``", ", found the end of the macro arm"), msg.1, ); } + if e.span.is_dummy() { // Get around lack of span in error (#30128) + e.replace_span_with(site_span); + if parser.sess.source_map().span_to_filename(arm_span).is_real() { + e.span_label(arm_span, "in this macro arm"); + } + } else if !parser.sess.source_map().span_to_filename(parser.span).is_real() { + e.span_label(site_span, "in this macro invocation"); + } e })); -- cgit 1.4.1-3-g733a5