Skip to content

Commit 040f1c0

Browse files
committed
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.
1 parent 0efc482 commit 040f1c0

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/libsyntax/ext/format.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl Context {
7676
self.ecx.span_err(sp, "expected token: `,`");
7777
return (extra, None);
7878
}
79+
if *p.token == token::EOF { break } // accept trailing commas
7980
if named || (token::is_ident(p.token) &&
8081
p.look_ahead(1, |t| *t == token::EQ)) {
8182
named = true;

src/test/run-pass/ifmt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ pub fn main() {
243243
}
244244

245245
test_format_args();
246+
247+
// test that trailing commas are acceptable
248+
format!("{}", "test",);
249+
format!("{foo}", foo="test",);
246250
}
247251

248252
// Basic test to make sure that we can invoke the `write!` macro with an

0 commit comments

Comments
 (0)