about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-03-05 10:06:50 -0800
committerbors <bors@rust-lang.org>2013-03-05 10:06:50 -0800
commite94465c053b06a5e4e0394812a12f4f6e027a98e (patch)
tree51048b6c635bd977b178c98d22d1950d1d59900a /src
parentafd6196d7b87401d20dc5149c6955e2c9758657f (diff)
parentfe08364b3be5463e28650a6ed8cdd203b775208a (diff)
auto merge of #5231 : jbclements/rust/better-macro-error-message, r=graydon
Macro invocations with path separators (e.g. foo::bar!()) now produce a sensible error message, rather than an assertion failure. Also added compile-fail test case.

Fixes #5218 ?
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/ext/expand.rs18
-rw-r--r--src/test/compile-fail/macro-with-seps-err-msg.rs17
2 files changed, 30 insertions, 5 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 97c75e65e1d..03633a89a86 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -37,10 +37,14 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
         // entry-point for all syntax extensions.
         expr_mac(ref mac) => {
             match (*mac).node {
-                // Token-tree macros, these will be the only case when we're
-                // finished transitioning.
+                // Token-tree macros:
                 mac_invoc_tt(pth, ref tts) => {
-                    assert (vec::len(pth.idents) == 1u);
+                    if (pth.idents.len() > 1u) {
+                        cx.span_fatal(
+                            pth.span,
+                            fmt!("expected macro name without module \
+                                  separators"));
+                    }
                     /* using idents and token::special_idents would make the
                     the macro names be hygienic */
                     let extname = cx.parse_sess().interner.get(pth.idents[0]);
@@ -319,8 +323,12 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
         }
         _ => return orig(s, sp, fld)
     };
-
-    assert(vec::len(pth.idents) == 1u);
+    if (pth.idents.len() > 1u) {
+        cx.span_fatal(
+            pth.span,
+            fmt!("expected macro name without module \
+                  separators"));
+    }
     let extname = cx.parse_sess().interner.get(pth.idents[0]);
     let (fully_expanded, sp) = match (*extsbox).find(&extname) {
         None =>
diff --git a/src/test/compile-fail/macro-with-seps-err-msg.rs b/src/test/compile-fail/macro-with-seps-err-msg.rs
new file mode 100644
index 00000000000..74c040238ac
--- /dev/null
+++ b/src/test/compile-fail/macro-with-seps-err-msg.rs
@@ -0,0 +1,17 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// error-pattern:expected macro name without module separators
+
+fn main() {
+    globnar::brotz!();
+}
+
+