about summary refs log tree commit diff
path: root/src/libsyntax/ext/tt
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-09-23 23:09:23 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-09-26 04:29:30 +0000
commitb90ceddcee2e7f4ed4236e6c52ddf8e585f3df6a (patch)
tree583c922fd2e8b1678f08b4a8872a533edde65f4b /src/libsyntax/ext/tt
parent4a8467b62d572eabedf50c09b52f177e87160e96 (diff)
downloadrust-b90ceddcee2e7f4ed4236e6c52ddf8e585f3df6a.tar.gz
rust-b90ceddcee2e7f4ed4236e6c52ddf8e585f3df6a.zip
Refactor `ensure_complete_parse`.
Diffstat (limited to 'src/libsyntax/ext/tt')
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs35
1 files changed, 11 insertions, 24 deletions
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index e78eeb8f7a4..d222de2dd36 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -39,32 +39,19 @@ pub struct ParserAnyMacro<'a> {
 }
 
 impl<'a> ParserAnyMacro<'a> {
-    /// Make sure we don't have any tokens left to parse, so we don't
-    /// silently drop anything. `allow_semi` is so that "optional"
-    /// semicolons at the end of normal expressions aren't complained
-    /// about e.g. the semicolon in `macro_rules! kapow { () => {
-    /// panic!(); } }` doesn't get picked up by .parse_expr(), but it's
-    /// allowed to be there.
-    fn ensure_complete_parse(&mut self, allow_semi: bool, context: &str) {
+    pub fn make(mut self: Box<ParserAnyMacro<'a>>, kind: ExpansionKind) -> Expansion {
         let ParserAnyMacro { site_span, macro_ident, ref mut parser } = *self;
-        parser.ensure_complete_parse(allow_semi, |parser| {
-            let token_str = parser.this_token_to_string();
-            let msg = format!("macro expansion ignores token `{}` and any \
-                               following",
-                              token_str);
-            let span = parser.span;
-            let mut err = parser.diagnostic().struct_span_err(span, &msg);
-            let msg = format!("caused by the macro expansion here; the usage \
-                               of `{}!` is likely invalid in {} context",
-                               macro_ident, context);
-            err.span_note(site_span, &msg)
-               .emit();
-        });
-    }
+        let expansion = panictry!(parser.parse_expansion(kind, true));
 
-    pub fn make(mut self: Box<ParserAnyMacro<'a>>, kind: ExpansionKind) -> Expansion {
-        let expansion = panictry!(self.parser.parse_expansion(kind, true));
-        self.ensure_complete_parse(kind == ExpansionKind::Expr, kind.name());
+        // We allow semicolons at the end of expressions -- e.g. the semicolon in
+        // `macro_rules! m { () => { panic!(); } }` isn't parsed by `.parse_expr()`,
+        // but `m!()` is allowed in expression positions (c.f. issue #34706).
+        if kind == ExpansionKind::Expr && parser.token == token::Semi {
+            parser.bump();
+        }
+
+        // Make sure we don't have any tokens left to parse so we don't silently drop anything.
+        parser.ensure_complete_parse(macro_ident.name, kind.name(), site_span);
         expansion
     }
 }