about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-11-05 12:25:31 -0800
committerEsteban Küber <esteban@kuber.com.ar>2018-11-23 15:37:31 -0800
commit76449d86c0c0b85ff93912a450012f2ece16c3d4 (patch)
tree79d3a48f7c1bb243ea3c97a0cf3f04650d4158f2 /src/libsyntax
parente5cd1edfa190442f4e3e0f53c0ac28f6cc9d15f3 (diff)
downloadrust-76449d86c0c0b85ff93912a450012f2ece16c3d4.tar.gz
rust-76449d86c0c0b85ff93912a450012f2ece16c3d4.zip
Point at macro arm when it doesn't expand to an expression
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index 5ce50f187d0..fa10d219ad6 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -45,16 +45,18 @@ pub struct ParserAnyMacro<'a> {
     /// Span of the expansion site of the macro this parser is for
     site_span: Span,
     /// The ident of the macro we're parsing
-    macro_ident: ast::Ident
+    macro_ident: ast::Ident,
+    arm_span: Span,
 }
 
 impl<'a> ParserAnyMacro<'a> {
     pub fn make(mut self: Box<ParserAnyMacro<'a>>, kind: AstFragmentKind) -> AstFragment {
-        let ParserAnyMacro { site_span, macro_ident, ref mut parser } = *self;
+        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));
             }
@@ -146,6 +148,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
                     quoted::TokenTree::Delimited(_, ref delimed) => delimed.tts.clone(),
                     _ => cx.span_bug(sp, "malformed macro rhs"),
                 };
+                let arm_span = rhses[i].span();
 
                 let rhs_spans = rhs.iter().map(|t| t.span()).collect::<Vec<_>>();
                 // rhs has holes ( `$id` and `$(...)` that need filled)
@@ -184,7 +187,8 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
                     // so we can print a useful error message if the parse of the expanded
                     // macro leaves unparsed tokens.
                     site_span: sp,
-                    macro_ident: name
+                    macro_ident: name,
+                    arm_span,
                 })
             }
             Failure(sp, tok, t) => if sp.lo() >= best_fail_spot.lo() {