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
Closes #15587
  • 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
@@ -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
@@ -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![]);
}

7 comments on commit c163eff

@bors
Copy link
Contributor

@bors bors commented on c163eff Jan 10, 2015

Choose a reason for hiding this comment

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

saw approval from alexcrichton
at Kimundi@c163eff

@bors
Copy link
Contributor

@bors bors commented on c163eff Jan 10, 2015

Choose a reason for hiding this comment

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

merging 8 batched pull requests into batch

@bors
Copy link
Contributor

@bors bors commented on c163eff Jan 10, 2015

Choose a reason for hiding this comment

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

status: {"merge_sha": "3b03c20c6ddaee5ba8b9797e988af1be42d612e2", "rollup_pulls": [[20771, "c163effc2b4704e3ec9d0011c90a8bd0bab4cb6c"], [20808, "4a7b710031de43c2d126ea42ac5f8b9c23201803"], [20817, "1a602c177908c3d6dcbf7d25817abfc11ddb2a6b"], [20818, "28723048a56a346dd23f06fa25cc174a195f4bc0"], [20819, "ba462b88e9f3ef217a264abe377963087d65728c"], [20833, "2a29296ea3f891f3216962d0ba8ada078a0657e6"], [20849, "d873aeeb923b733f86c89f4a9fc599770a170640"], [20851, "68ecfe0b61d85f4afbe5a25bcfc74cacdcb3ad47"]]}

@bors
Copy link
Contributor

@bors bors commented on c163eff Jan 10, 2015

Choose a reason for hiding this comment

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

Testing rollup candidate = 3b03c20

Successful merges:

@bors
Copy link
Contributor

@bors bors commented on c163eff Jan 10, 2015

Choose a reason for hiding this comment

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

fast-forwarding master to auto = 3b03c20

@bors
Copy link
Contributor

@bors bors commented on c163eff Jan 10, 2015

Choose a reason for hiding this comment

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

fast-forwarding master to auto = 3b03c20

Please sign in to comment.