@@ -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-
496479impl < 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