diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2018-11-05 16:27:28 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2018-11-23 15:37:31 -0800 |
| commit | c45871ba02430c3af6453d5636f8ad0afb7eb35f (patch) | |
| tree | 49b8c1951ef8b2bd5207fe9385d7792299a4a7dd /src/libsyntax/ext | |
| parent | 76449d86c0c0b85ff93912a450012f2ece16c3d4 (diff) | |
| download | rust-c45871ba02430c3af6453d5636f8ad0afb7eb35f.tar.gz rust-c45871ba02430c3af6453d5636f8ad0afb7eb35f.zip | |
Keep label on moved spans and point at macro invocation on parse error
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 20 |
1 files changed, 12 insertions, 8 deletions
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<ParserAnyMacro<'a>>, 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 `<eof>`") { + 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 `<eof>`", ", 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 })); |
