auto merge of : 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  ?
This commit is contained in:
bors 2013-03-05 10:06:50 -08:00
commit e94465c053
2 changed files with 30 additions and 5 deletions
src
libsyntax/ext
test/compile-fail

@ -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 =>

@ -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!();
}