diff options
| author | bors <bors@rust-lang.org> | 2015-01-10 14:15:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-10 14:15:09 +0000 |
| commit | c0ca57a6fb176d8082eac0ba1de4690f4c0eb0bb (patch) | |
| tree | b3a13c02de8a52c28bf07b1caae734b2a4968db6 | |
| parent | a09b139f9c4c6f4a2c3fb78e906e3ae0abf7f901 (diff) | |
| parent | c163effc2b4704e3ec9d0011c90a8bd0bab4cb6c (diff) | |
| download | rust-c0ca57a6fb176d8082eac0ba1de4690f4c0eb0bb.tar.gz rust-c0ca57a6fb176d8082eac0ba1de4690f4c0eb0bb.zip | |
Merge pull request #20771 from Kimundi/vec-macro-repeat
Enabled the `vec![]` macro to use the `[a; b]` repeat syntax. Reviewed-by: alexcrichton
| -rw-r--r-- | src/libcollections/macros.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/vec-macro-repeat.rs | 17 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/libcollections/macros.rs b/src/libcollections/macros.rs index 0ff869d6183..c078db7d46f 100644 --- a/src/libcollections/macros.rs +++ b/src/libcollections/macros.rs @@ -1,4 +1,4 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -12,6 +12,10 @@ #[macro_export] #[stable] macro_rules! vec { + ($x:expr; $y:expr) => ({ + let xs: $crate::boxed::Box<[_]> = $crate::boxed::Box::new([$x; $y]); + $crate::slice::SliceExt::into_vec(xs) + }); ($($x:expr),*) => ({ let xs: $crate::boxed::Box<[_]> = $crate::boxed::Box::new([$($x),*]); $crate::slice::SliceExt::into_vec(xs) diff --git a/src/test/run-pass/vec-macro-repeat.rs b/src/test/run-pass/vec-macro-repeat.rs new file mode 100644 index 00000000000..9e69ecfce4f --- /dev/null +++ b/src/test/run-pass/vec-macro-repeat.rs @@ -0,0 +1,17 @@ +// Copyright 2015 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; 3], vec![1, 1, 1]); + assert_eq!(vec![1; 2], vec![1, 1]); + assert_eq!(vec![1; 1], vec![1]); + assert_eq!(vec![1; 0], vec![]); +} |
