From 016a4b0f37331166b84ea2a35a494a4e47bb1143 Mon Sep 17 00:00:00 2001
From: Kang Seonghoon <public+git@mearie.org>
Date: Thu, 3 Apr 2014 16:40:56 +0900
Subject: [PATCH] std: make vec!() macro handle a trailing comma

Fixes #12910.
---
 src/libstd/macros.rs                              |  3 ++-
 .../compile-fail/vec-macro-with-comma-only.rs     | 13 +++++++++++++
 .../run-pass/vec-macro-with-trailing-comma.rs     | 15 +++++++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 src/test/compile-fail/vec-macro-with-comma-only.rs
 create mode 100644 src/test/run-pass/vec-macro-with-trailing-comma.rs

diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index 9b1c5a406cf69..0ea03eaee18ac 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -273,7 +273,8 @@ macro_rules! vec(
         let mut _temp = ::std::vec::Vec::new();
         $(_temp.push($e);)*
         _temp
-    })
+    });
+    ($($e:expr),+,) => (vec!($($e),+))
 )
 
 
diff --git a/src/test/compile-fail/vec-macro-with-comma-only.rs b/src/test/compile-fail/vec-macro-with-comma-only.rs
new file mode 100644
index 0000000000000..8c8e789cd9640
--- /dev/null
+++ b/src/test/compile-fail/vec-macro-with-comma-only.rs
@@ -0,0 +1,13 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub fn main() {
+    vec!(,); //~ ERROR unexpected token
+}
diff --git a/src/test/run-pass/vec-macro-with-trailing-comma.rs b/src/test/run-pass/vec-macro-with-trailing-comma.rs
new file mode 100644
index 0000000000000..07033d6049747
--- /dev/null
+++ b/src/test/run-pass/vec-macro-with-trailing-comma.rs
@@ -0,0 +1,15 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+pub fn main() {
+    assert_eq!(vec!(1), vec!(1,));
+    assert_eq!(vec!(1, 2, 3), vec!(1, 2, 3,));
+}