提交 5afb3d20 编写于 作者: B Birunthan Mohanathas 提交者: Daniel Micay

Disallow non-comma-delimited arguments to fmt! and bytes!

Closes #4982.
上级 6c88e46d
......@@ -232,7 +232,7 @@ pub fn report_error_if_loan_conflicts_with_restriction(&self,
self.bccx.span_err(
new_loan.span,
fmt!("cannot borrow `%s` as %s because \
it is also borrowed as %s"
it is also borrowed as %s",
self.bccx.loan_path_to_str(new_loan.loan_path),
self.bccx.mut_to_str(new_loan.mutbl),
self.bccx.mut_to_str(old_loan.mutbl)));
......@@ -320,7 +320,7 @@ pub fn check_assignment(&self, expr: @ast::expr) {
// Otherwise, just a plain error.
self.bccx.span_err(
expr.span,
fmt!("cannot assign to %s %s"
fmt!("cannot assign to %s %s",
cmt.mutbl.to_user_str(),
self.bccx.cmt_to_str(cmt)));
return;
......
......@@ -357,15 +357,16 @@ pub fn get_single_str_from_tts(cx: @ExtCtxt,
}
}
pub fn get_exprs_from_tts(cx: @ExtCtxt, tts: &[ast::token_tree])
-> ~[@ast::expr] {
pub fn get_exprs_from_tts(cx: @ExtCtxt,
sp: span,
tts: &[ast::token_tree]) -> ~[@ast::expr] {
let p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(),
tts.to_owned());
let mut es = ~[];
while *p.token != token::EOF {
if es.len() != 0 {
p.eat(&token::COMMA);
if es.len() != 0 && !p.eat(&token::COMMA) {
cx.span_fatal(sp, "expected token: `,`");
}
es.push(p.parse_expr());
}
......
......@@ -18,7 +18,7 @@
pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult {
// Gather all argument expressions
let exprs = get_exprs_from_tts(cx, tts);
let exprs = get_exprs_from_tts(cx, sp, tts);
let mut bytes = ~[];
for exprs.iter().advance |expr| {
......
......@@ -26,7 +26,7 @@
pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
-> base::MacResult {
let args = get_exprs_from_tts(cx, tts);
let args = get_exprs_from_tts(cx, sp, tts);
if args.len() == 0 {
cx.span_fatal(sp, "fmt! takes at least 1 argument.");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册