Skip to content

Commit

Permalink
Enabled the vec![] macro to use the [a; b] repeat syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimundi committed Jan 8, 2015
1 parent 2f99a41 commit c163eff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libcollections/macros.rs
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions src/test/run-pass/vec-macro-repeat.rs
Original file line number Diff line number Diff line change
@@ -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![]);
}

1 comment on commit c163eff

@alexcrichton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+ rollup

Please sign in to comment.