Skip to content

Commit 1975a3d

Browse files
committed
Temporarily revert Default implementation back to old macro-based one.
1 parent e9cbd50 commit 1975a3d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/libcore/array.rs

+33
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,42 @@ impl<T:Ord, const N: usize> Ord for [T; N] {
313313
}
314314
}
315315

316+
/*
317+
316318
#[stable(since = "1.4.0", feature = "array_default")]
317319
impl<T, const N: usize> Default for [T; N] where T: Default {
318320
fn default() -> [T; N] {
319321
[T::default(); N]
320322
}
321323
}
324+
325+
// FIXME: This doesn't work now because it's using negative bound.
326+
327+
#[stable(since = "1.4.0", feature = "array_default")]
328+
impl<T> Default for [T; 0] where T: !Default {
329+
fn default() -> [T; 0] {
330+
[]
331+
}
332+
}
333+
334+
*/
335+
336+
macro_rules! array_impl_default {
337+
{$n:expr, $t:ident $($ts:ident)*} => {
338+
#[stable(since = "1.4.0", feature = "array_default")]
339+
impl<T> Default for [T; $n] where T: Default {
340+
fn default() -> [T; $n] {
341+
[$t::default(), $($ts::default()),*]
342+
}
343+
}
344+
array_impl_default!{($n - 1), $($ts)*}
345+
};
346+
{$n:expr,} => {
347+
#[stable(since = "1.4.0", feature = "array_default")]
348+
impl<T> Default for [T; $n] {
349+
fn default() -> [T; $n] { [] }
350+
}
351+
};
352+
}
353+
354+
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}

0 commit comments

Comments
 (0)