Skip to content

Better macro error message #5231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
/* using idents and token::special_idents would make the
the macro names be hygienic */
let extname = cx.parse_sess().interner.get(pth.idents[0]);
Expand Down Expand Up @@ -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"));
}
let extname = cx.parse_sess().interner.get(pth.idents[0]);
let (fully_expanded, sp) = match (*extsbox).find(&extname) {
None =>
Expand Down
17 changes: 17 additions & 0 deletions src/test/compile-fail/macro-with-seps-err-msg.rs
Original file line number Diff line number Diff line change
@@ -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!();
}