Skip to content

Commit e94465c

Browse files
committed
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 ?
2 parents afd6196 + fe08364 commit e94465c

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
3737
// entry-point for all syntax extensions.
3838
expr_mac(ref mac) => {
3939
match (*mac).node {
40-
// Token-tree macros, these will be the only case when we're
41-
// finished transitioning.
40+
// Token-tree macros:
4241
mac_invoc_tt(pth, ref tts) => {
43-
assert (vec::len(pth.idents) == 1u);
42+
if (pth.idents.len() > 1u) {
43+
cx.span_fatal(
44+
pth.span,
45+
fmt!("expected macro name without module \
46+
separators"));
47+
}
4448
/* using idents and token::special_idents would make the
4549
the macro names be hygienic */
4650
let extname = cx.parse_sess().interner.get(pth.idents[0]);
@@ -319,8 +323,12 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
319323
}
320324
_ => return orig(s, sp, fld)
321325
};
322-
323-
assert(vec::len(pth.idents) == 1u);
326+
if (pth.idents.len() > 1u) {
327+
cx.span_fatal(
328+
pth.span,
329+
fmt!("expected macro name without module \
330+
separators"));
331+
}
324332
let extname = cx.parse_sess().interner.get(pth.idents[0]);
325333
let (fully_expanded, sp) = match (*extsbox).find(&extname) {
326334
None =>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:expected macro name without module separators
12+
13+
fn main() {
14+
globnar::brotz!();
15+
}
16+
17+

0 commit comments

Comments
 (0)