Skip to content

Commit 0a40a57

Browse files
committed
test: make [T; N]::default use const generics
1 parent 02c7b1a commit 0a40a57

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

library/core/src/array/mod.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -469,30 +469,13 @@ impl<T: Copy> SpecArrayClone for T {
469469
}
470470
}
471471

472-
// The Default impls cannot be done with const generics because `[T; 0]` doesn't
473-
// require Default to be implemented, and having different impl blocks for
474-
// different numbers isn't supported yet.
475-
476-
macro_rules! array_impl_default {
477-
{$n:expr, $t:ident $($ts:ident)*} => {
478-
#[stable(since = "1.4.0", feature = "array_default")]
479-
impl<T> Default for [T; $n] where T: Default {
480-
fn default() -> [T; $n] {
481-
[$t::default(), $($ts::default()),*]
482-
}
483-
}
484-
array_impl_default!{($n - 1), $($ts)*}
485-
};
486-
{$n:expr,} => {
487-
#[stable(since = "1.4.0", feature = "array_default")]
488-
impl<T> Default for [T; $n] {
489-
fn default() -> [T; $n] { [] }
490-
}
491-
};
472+
#[stable(since = "1.4.0", feature = "array_default")]
473+
impl<T: Default, const N: usize> Default for [T; N] {
474+
fn default() -> Self {
475+
from_fn(|_| { T::default() })
476+
}
492477
}
493478

494-
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}
495-
496479
impl<T, const N: usize> [T; N] {
497480
/// Returns an array of the same size as `self`, with function `f` applied to each element
498481
/// in order.

0 commit comments

Comments
 (0)