Skip to content

Commit 339295a

Browse files
committed
Disallow non-comma-delimited arguments to fmt! and bytes!
Closes #4982.
1 parent 7a3eaf8 commit 339295a

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

src/librustc/middle/borrowck/check_loans.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<'self> CheckLoanCtxt<'self> {
232232
self.bccx.span_err(
233233
new_loan.span,
234234
fmt!("cannot borrow `%s` as %s because \
235-
it is also borrowed as %s"
235+
it is also borrowed as %s",
236236
self.bccx.loan_path_to_str(new_loan.loan_path),
237237
self.bccx.mut_to_str(new_loan.mutbl),
238238
self.bccx.mut_to_str(old_loan.mutbl)));
@@ -320,7 +320,7 @@ impl<'self> CheckLoanCtxt<'self> {
320320
// Otherwise, just a plain error.
321321
self.bccx.span_err(
322322
expr.span,
323-
fmt!("cannot assign to %s %s"
323+
fmt!("cannot assign to %s %s",
324324
cmt.mutbl.to_user_str(),
325325
self.bccx.cmt_to_str(cmt)));
326326
return;

src/libsyntax/ext/base.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,16 @@ pub fn get_single_str_from_tts(cx: @ExtCtxt,
357357
}
358358
}
359359

360-
pub fn get_exprs_from_tts(cx: @ExtCtxt, tts: &[ast::token_tree])
361-
-> ~[@ast::expr] {
360+
pub fn get_exprs_from_tts(cx: @ExtCtxt,
361+
sp: span,
362+
tts: &[ast::token_tree]) -> ~[@ast::expr] {
362363
let p = parse::new_parser_from_tts(cx.parse_sess(),
363364
cx.cfg(),
364365
tts.to_owned());
365366
let mut es = ~[];
366367
while *p.token != token::EOF {
367-
if es.len() != 0 {
368-
p.eat(&token::COMMA);
368+
if es.len() != 0 && !p.eat(&token::COMMA) {
369+
cx.span_fatal(sp, "expected token: `,`");
369370
}
370371
es.push(p.parse_expr());
371372
}

src/libsyntax/ext/bytes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use ext::build::AstBuilder;
1818

1919
pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult {
2020
// Gather all argument expressions
21-
let exprs = get_exprs_from_tts(cx, tts);
21+
let exprs = get_exprs_from_tts(cx, sp, tts);
2222
let mut bytes = ~[];
2323

2424
for exprs.iter().advance |expr| {

src/libsyntax/ext/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use parse::token::{str_to_ident};
2626

2727
pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
2828
-> base::MacResult {
29-
let args = get_exprs_from_tts(cx, tts);
29+
let args = get_exprs_from_tts(cx, sp, tts);
3030
if args.len() == 0 {
3131
cx.span_fatal(sp, "fmt! takes at least 1 argument.");
3232
}

0 commit comments

Comments
 (0)