diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index d14419a23a1d8..45736279bc526 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -469,30 +469,13 @@ impl SpecArrayClone for T { } } -// The Default impls cannot be done with const generics because `[T; 0]` doesn't -// require Default to be implemented, and having different impl blocks for -// different numbers isn't supported yet. - -macro_rules! array_impl_default { - {$n:expr, $t:ident $($ts:ident)*} => { - #[stable(since = "1.4.0", feature = "array_default")] - impl Default for [T; $n] where T: Default { - fn default() -> [T; $n] { - [$t::default(), $($ts::default()),*] - } - } - array_impl_default!{($n - 1), $($ts)*} - }; - {$n:expr,} => { - #[stable(since = "1.4.0", feature = "array_default")] - impl Default for [T; $n] { - fn default() -> [T; $n] { [] } - } - }; +#[stable(since = "1.4.0", feature = "array_default")] +impl Default for [T; N] { + fn default() -> Self { + from_fn(|_| T::default()) + } } -array_impl_default! {32, T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T} - impl [T; N] { /// Returns an array of the same size as `self`, with function `f` applied to each element /// in order.