From 3ae2d21c12a1fbe909f72a96b012d7092c5419e4 Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 9 Apr 2020 11:03:57 +0300 Subject: [PATCH 1/2] simplify `vec!` macro Simplify `vec!` macro by replacing 2 following branches: - `($($x:expr),*) => (...)` - `($($x:expr,)*) => (...)` with one: - `($($x:expr),* $(,)?) => (...)` --- src/liballoc/macros.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/liballoc/macros.rs b/src/liballoc/macros.rs index 4bc0c3a079d..4a613b92ce8 100644 --- a/src/liballoc/macros.rs +++ b/src/liballoc/macros.rs @@ -42,10 +42,9 @@ macro_rules! vec { ($elem:expr; $n:expr) => ( $crate::vec::from_elem($elem, $n) ); - ($($x:expr),*) => ( + ($($x:expr),* $(,)?) => ( <[_]>::into_vec(box [$($x),*]) ); - ($($x:expr,)*) => ($crate::vec![$($x),*]) } // HACK(japaric): with cfg(test) the inherent `[T]::into_vec` method, which is From 2c23bd491445c56d2f5e8b22df572dbf9944ee62 Mon Sep 17 00:00:00 2001 From: Waffle Date: Tue, 14 Apr 2020 10:27:55 +0300 Subject: [PATCH 2/2] make `vec![,]` uncompilable Fix regression introduced in commit #3ae2d21 --- src/liballoc/macros.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liballoc/macros.rs b/src/liballoc/macros.rs index 4a613b92ce8..e163a166b49 100644 --- a/src/liballoc/macros.rs +++ b/src/liballoc/macros.rs @@ -42,8 +42,8 @@ macro_rules! vec { ($elem:expr; $n:expr) => ( $crate::vec::from_elem($elem, $n) ); - ($($x:expr),* $(,)?) => ( - <[_]>::into_vec(box [$($x),*]) + ($($x:expr),+ $(,)?) => ( + <[_]>::into_vec(box [$($x),+]) ); }