Skip to content

Commit 9bd84fd

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 193829 b: refs/heads/beta c: 633c593 h: refs/heads/master i: 193827: be93244 v: v3
1 parent b8de29b commit 9bd84fd

File tree

26 files changed

+944
-1
lines changed

26 files changed

+944
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: 5b118f5ecde796ad62fa349a045d7ad8129b711c
34+
refs/heads/beta: 633c593bc3f9787decfaf943cdc5659f132ade50
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3737
refs/heads/tmp: de8a23bbc3a7b9cbd7574b5b91a34af59bf030e6

branches/beta/src/libcollections/macros.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[cfg(stage0)]
1112
/// Creates a `Vec` containing the arguments.
1213
///
1314
/// `vec!` allows `Vec`s to be defined with the same syntax as array expressions.
@@ -45,6 +46,43 @@ macro_rules! vec {
4546
($($x:expr,)*) => (vec![$($x),*])
4647
}
4748

49+
#[cfg(not(stage0))]
50+
/// Creates a `Vec` containing the arguments.
51+
///
52+
/// `vec!` allows `Vec`s to be defined with the same syntax as array expressions.
53+
/// There are two forms of this macro:
54+
///
55+
/// - Create a `Vec` containing a given list of elements:
56+
///
57+
/// ```
58+
/// let v = vec![1, 2, 3];
59+
/// assert_eq!(v[0], 1);
60+
/// assert_eq!(v[1], 2);
61+
/// assert_eq!(v[2], 3);
62+
/// ```
63+
///
64+
/// - Create a `Vec` from a given element and size:
65+
///
66+
/// ```
67+
/// let v = vec![1; 3];
68+
/// assert_eq!(v, [1, 1, 1]);
69+
/// ```
70+
///
71+
/// Note that unlike array expressions this syntax supports all elements
72+
/// which implement `Clone` and the number of elements doesn't have to be
73+
/// a constant.
74+
#[macro_export]
75+
#[stable(feature = "rust1", since = "1.0.0")]
76+
macro_rules! vec {
77+
($elem:expr; $n:expr) => (
78+
$crate::vec::from_elem($elem, $n)
79+
);
80+
($($x:expr),*) => (
81+
<[_]>::into_vec($crate::boxed::Box::new([$($x),*]))
82+
);
83+
($($x:expr,)*) => (vec![$($x),*])
84+
}
85+
4886
/// Use the syntax described in `std::fmt` to create a value of type `String`.
4987
/// See `std::fmt` for more information.
5088
///

0 commit comments

Comments
 (0)