Skip to content

Commit da29a8e

Browse files
committed
auto merge of #9299 : alexcrichton/rust/fmt-trailing-comma, r=huonw
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.
2 parents 99ec14d + 040f1c0 commit da29a8e

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/libsyntax/ext/format.rs

+1
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

+4
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)