"inline assembly must be a string literal.") {
Some((s, st)) => (s, st),
// let compilation continue
- None => return MacResult::dummy_expr(),
+ None => return MacResult::dummy_expr(sp),
};
asm = s;
asm_str_style = Some(style);
fn make_stmt(&self) -> @ast::Stmt;
}
+
pub enum MacResult {
MRExpr(@ast::Expr),
MRItem(@ast::Item),
/// type signatures after emitting a non-fatal error (which stop
/// compilation well before the validity (or otherwise)) of the
/// expression are checked.
- pub fn dummy_expr() -> MacResult {
- MRExpr(@ast::Expr {
- id: ast::DUMMY_NODE_ID, node: ast::ExprLogLevel, span: codemap::DUMMY_SP
- })
+ pub fn raw_dummy_expr(sp: codemap::Span) -> @ast::Expr {
+ @ast::Expr {
+ id: ast::DUMMY_NODE_ID,
+ node: ast::ExprLogLevel,
+ span: sp
+ }
+ }
+ pub fn dummy_expr(sp: codemap::Span) -> MacResult {
+ MRExpr(MacResult::raw_dummy_expr(sp))
}
}
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult {
// Gather all argument expressions
let exprs = match get_exprs_from_tts(cx, sp, tts) {
- None => return MacResult::dummy_expr(),
+ None => return MacResult::dummy_expr(sp),
Some(e) => e,
};
let mut bytes = ~[];
tts: &[ast::TokenTree]) -> base::MacResult {
let es = match base::get_exprs_from_tts(cx, sp, tts) {
Some(e) => e,
- None => return base::MacResult::dummy_expr()
+ None => return base::MacResult::dummy_expr(sp)
};
let mut accumulator = ~"";
for e in es.move_iter() {
ast::TTTok(_, token::COMMA) => (),
_ => {
cx.span_err(sp, "concat_idents! expecting comma.");
- return MacResult::dummy_expr();
+ return MacResult::dummy_expr(sp);
}
}
} else {
}
_ => {
cx.span_err(sp, "concat_idents! requires ident args.");
- return MacResult::dummy_expr();
+ return MacResult::dummy_expr(sp);
}
}
}
pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> base::MacResult {
let var = match get_single_str_from_tts(cx, sp, tts, "option_env!") {
- None => return MacResult::dummy_expr(),
+ None => return MacResult::dummy_expr(sp),
Some(v) => v
};
let exprs = match get_exprs_from_tts(cx, sp, tts) {
Some([]) => {
cx.span_err(sp, "env! takes 1 or 2 arguments");
- return MacResult::dummy_expr();
+ return MacResult::dummy_expr(sp);
}
- None => return MacResult::dummy_expr(),
+ None => return MacResult::dummy_expr(sp),
Some(exprs) => exprs
};
let var = match expr_to_str(cx, exprs[0], "expected string literal") {
- None => return MacResult::dummy_expr(),
+ None => return MacResult::dummy_expr(sp),
Some((v, _style)) => v
};
let msg = match exprs.len() {
}
2 => {
match expr_to_str(cx, exprs[1], "expected string literal") {
- None => return MacResult::dummy_expr(),
+ None => return MacResult::dummy_expr(sp),
Some((s, _style)) => s
}
}
_ => {
cx.span_err(sp, "env! takes 1 or 2 arguments");
- return MacResult::dummy_expr();
+ return MacResult::dummy_expr(sp);
}
};
format!("expected macro name without module \
separators"));
// let compilation continue
- return e;
+ return MacResult::raw_dummy_expr(e.span);
}
let extname = pth.segments[0].identifier;
let extnamestr = token::get_ident(extname);
extnamestr.get()));
// let compilation continue
- return e;
+ return MacResult::raw_dummy_expr(e.span);
}
Some(&NormalTT(ref expandfun, exp_span)) => {
fld.cx.bt_push(ExpnInfo {
extnamestr.get()
)
);
- return e;
+ return MacResult::raw_dummy_expr(e.span);
}
};
format!("'{}' is not a tt-style macro",
extnamestr.get())
);
- return e;
+ return MacResult::raw_dummy_expr(e.span);
}
};
expr,
"format argument must be a string literal.") {
Some((fmt, _)) => fmt,
- None => return efmt
+ None => return MacResult::raw_dummy_expr(sp)
};
let mut parser = parse::Parser::new(fmt.get());
match parser.errors.shift() {
Some(error) => {
cx.ecx.span_err(efmt.span, "invalid format string: " + error);
- return efmt;
+ return MacResult::raw_dummy_expr(sp);
}
None => {}
}
-> base::MacResult {
let file = match get_single_str_from_tts(cx, sp, tts, "include!") {
Some(f) => f,
- None => return MacResult::dummy_expr(),
+ None => return MacResult::dummy_expr(sp),
};
// The file will be added to the code map by the parser
let mut p =
-> base::MacResult {
let file = match get_single_str_from_tts(cx, sp, tts, "include_str!") {
Some(f) => f,
- None => return MacResult::dummy_expr()
+ None => return MacResult::dummy_expr(sp)
};
let file = res_rel_file(cx, sp, &Path::new(file));
let bytes = match File::open(&file).read_to_end() {
Err(e) => {
cx.span_err(sp, format!("couldn't read {}: {}", file.display(), e));
- return MacResult::dummy_expr();
+ return MacResult::dummy_expr(sp);
}
Ok(bytes) => bytes,
};
}
None => {
cx.span_err(sp, format!("{} wasn't a utf-8 file", file.display()));
- return MacResult::dummy_expr();
+ return MacResult::dummy_expr(sp);
}
}
}
{
let file = match get_single_str_from_tts(cx, sp, tts, "include_bin!") {
Some(f) => f,
- None => return MacResult::dummy_expr()
+ None => return MacResult::dummy_expr(sp)
};
let file = res_rel_file(cx, sp, &Path::new(file));
match File::open(&file).read_to_end() {
Err(e) => {
cx.span_err(sp, format!("couldn't read {}: {}", file.display(), e));
- return MacResult::dummy_expr();
+ return MacResult::dummy_expr(sp);
}
Ok(bytes) => {
base::MRExpr(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes))))
cx.set_trace_macros(false);
} else {
cx.span_err(sp, "trace_macros! only accepts `true` or `false`");
- return base::MacResult::dummy_expr();
+ return base::MacResult::dummy_expr(sp);
}
rust_parser.bump();
--- /dev/null
+// Copyright 2014 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.
+
+fn main() {
+ print!(test!());
+ //~^ ERROR: macro undefined: 'test'
+ //~^^ ERROR: format argument must be a string literal
+
+ concat!(test!());
+ //~^ ERROR: macro undefined: 'test'
+ //~^^ ERROR: expected a literal
+}