about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-09-18 13:51:07 -0700
committerAlex Crichton <alex@alexcrichton.com>2013-09-18 13:51:07 -0700
commit040f1c06bc7c1c5fa37477513227114d343b3ec3 (patch)
tree379c2fff23fd4e7f4ca7defe2cd1b13ef59ca1b1 /src
parent0efc4822e93221714aa7d142de44a057bdbad2ca (diff)
downloadrust-040f1c06bc7c1c5fa37477513227114d343b3ec3.tar.gz
rust-040f1c06bc7c1c5fa37477513227114d343b3ec3.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/ext/format.rs1
-rw-r--r--src/test/run-pass/ifmt.rs4
2 files changed, 5 insertions, 0 deletions
diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs
index 9f4e55b1a92..cace4648df2 100644
--- a/src/libsyntax/ext/format.rs
+++ b/src/libsyntax/ext/format.rs
@@ -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;
diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs
index 351bad193da..6ca21c6c5a1 100644
--- a/src/test/run-pass/ifmt.rs
+++ b/src/test/run-pass/ifmt.rs
@@ -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