diff options
| author | Kang Seonghoon <public+git@mearie.org> | 2014-04-03 16:40:56 +0900 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-04-08 00:03:12 -0700 |
| commit | 7a281718f0d32ea678f031252c0e130035fc2a80 (patch) | |
| tree | 0751e90a71066c425bd96185e80fbfbf4b0a7c12 | |
| parent | 87334fb05ff2a665419241d877c13d6c4770a3f4 (diff) | |
| download | rust-7a281718f0d32ea678f031252c0e130035fc2a80.tar.gz rust-7a281718f0d32ea678f031252c0e130035fc2a80.zip | |
std: make vec!() macro handle a trailing comma
Fixes #12910.
| -rw-r--r-- | src/libstd/macros.rs | 3 | ||||
| -rw-r--r-- | src/test/compile-fail/vec-macro-with-comma-only.rs | 13 | ||||
| -rw-r--r-- | src/test/run-pass/vec-macro-with-trailing-comma.rs | 15 |
3 files changed, 30 insertions, 1 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 1a35252f8ca..fbb48f2ebcb 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 00000000000..8c8e789cd96 --- /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 00000000000..07033d60497 --- /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,)); +} |
