From 73806ddd0fd91066d7b903a00a080cbadcc04311 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 15 Sep 2014 19:29:47 -0700 Subject: Use $crate and macro reexport to reduce duplicated code Many of libstd's macros are now re-exported from libcore and libcollections. Their libstd definitions have moved to a macros_stage0 module and can disappear after the next snapshot. Where the two crates had already diverged, I took the libstd versions as they're generally newer and better-tested. See e.g. d3c831b, which was a fix to libstd's assert_eq!() that didn't make it into libcore's. Fixes #16806. --- src/libcollections/lib.rs | 3 +++ src/libcollections/macros.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+) (limited to 'src/libcollections') diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index db236795038..27ab791b604 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -51,6 +51,9 @@ pub use string::String; pub use vec::Vec; pub use vec_map::VecMap; +// Needed for the vec! macro +pub use alloc::boxed; + mod macros; pub mod binary_heap; diff --git a/src/libcollections/macros.rs b/src/libcollections/macros.rs index ce4b1e46773..0dbc71269a6 100644 --- a/src/libcollections/macros.rs +++ b/src/libcollections/macros.rs @@ -11,6 +11,8 @@ #![macro_escape] /// Creates a `std::vec::Vec` containing the arguments. +// NOTE: remove after the next snapshot +#[cfg(stage0)] macro_rules! vec { ($($e:expr),*) => ({ // leading _ to allow empty construction without a warning. @@ -21,3 +23,13 @@ macro_rules! vec { ($($e:expr),+,) => (vec!($($e),+)) } +/// Creates a `Vec` containing the arguments. +#[cfg(not(stage0))] +#[macro_export] +macro_rules! vec { + ($($x:expr),*) => ({ + let xs: $crate::boxed::Box<[_]> = box [$($x),*]; + $crate::slice::SliceExt::into_vec(xs) + }); + ($($x:expr,)*) => (vec![$($x),*]) +} -- cgit 1.4.1-3-g733a5