From 4f3a968f91bbc2991056e1fb7e6e38829bbce57d Mon Sep 17 00:00:00 2001 From: John Clements Date: Mon, 4 Mar 2013 13:58:31 -0800 Subject: [PATCH 1/3] better error message for macros with MOD_SEPs --- src/libsyntax/ext/expand.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 858ce4b17a3ef..ce8bf797ddba2 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -38,10 +38,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, got: '%?'",pth)); + } /* using idents and token::special_idents would make the the macro names be hygienic */ let extname = cx.parse_sess().interner.get(pth.idents[0]); @@ -320,8 +324,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, got: '%?'",pth)); + } let extname = cx.parse_sess().interner.get(pth.idents[0]); let (fully_expanded, sp) = match (*extsbox).find(&extname) { None => From a191babbe56170380c6d9b6a26ebf472b7c5dd37 Mon Sep 17 00:00:00 2001 From: John Clements Date: Mon, 4 Mar 2013 16:50:52 -0800 Subject: [PATCH 2/3] simplified msg (TMI on old one) --- src/libsyntax/ext/expand.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ce8bf797ddba2..cb04b2c55ae55 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -44,7 +44,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, cx.span_fatal( pth.span, fmt!("expected macro name without module \ - separators, got: '%?'",pth)); + separators")); } /* using idents and token::special_idents would make the the macro names be hygienic */ @@ -328,7 +328,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, cx.span_fatal( pth.span, fmt!("expected macro name without module \ - separators, got: '%?'",pth)); + separators")); } let extname = cx.parse_sess().interner.get(pth.idents[0]); let (fully_expanded, sp) = match (*extsbox).find(&extname) { From fe08364b3be5463e28650a6ed8cdd203b775208a Mon Sep 17 00:00:00 2001 From: John Clements Date: Mon, 4 Mar 2013 17:36:44 -0800 Subject: [PATCH 3/3] added test case for macros with separators error message --- .../compile-fail/macro-with-seps-err-msg.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/compile-fail/macro-with-seps-err-msg.rs 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 0000000000000..74c040238ac05 --- /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 or the MIT license +// , 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!(); +} + +