Allow trailing commas in format!

This is more consistent with other parts of the language and it also makes it
easier to use in situations where format string is massive.
This commit is contained in:
Alex Crichton 2013-09-18 13:51:07 -07:00
parent 0efc4822e9
commit 040f1c06bc
2 changed files with 5 additions and 0 deletions

View File

@ -76,6 +76,7 @@ impl Context {
self.ecx.span_err(sp, "expected token: `,`");
return (extra, None);
}
if *p.token == token::EOF { break } // accept trailing commas
if named || (token::is_ident(p.token) &&
p.look_ahead(1, |t| *t == token::EQ)) {
named = true;

View File

@ -243,6 +243,10 @@ pub fn main() {
}
test_format_args();
// test that trailing commas are acceptable
format!("{}", "test",);
format!("{foo}", foo="test",);
}
// Basic test to make sure that we can invoke the `write!` macro with an