Added const Default impls for Arrays and Tuples.

This commit is contained in:
onestacked 2022-09-23 17:53:59 +02:00
parent 4d44e09cb1
commit 449326aaad
2 changed files with 4 additions and 2 deletions

View File

@ -434,7 +434,8 @@ impl<T: Copy> SpecArrayClone for T {
macro_rules! array_impl_default { macro_rules! array_impl_default {
{$n:expr, $t:ident $($ts:ident)*} => { {$n:expr, $t:ident $($ts:ident)*} => {
#[stable(since = "1.4.0", feature = "array_default")] #[stable(since = "1.4.0", feature = "array_default")]
impl<T> Default for [T; $n] where T: Default { #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
impl<T> const Default for [T; $n] where T: ~const Default {
fn default() -> [T; $n] { fn default() -> [T; $n] {
[$t::default(), $($ts::default()),*] [$t::default(), $($ts::default()),*]
} }

View File

@ -93,7 +93,8 @@ macro_rules! tuple_impls {
maybe_tuple_doc! { maybe_tuple_doc! {
$($T)+ @ $($T)+ @
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<$($T:Default),+> Default for ($($T,)+) { #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
impl<$($T: ~const Default),+> const Default for ($($T,)+) {
#[inline] #[inline]
fn default() -> ($($T,)+) { fn default() -> ($($T,)+) {
($({ let x: $T = Default::default(); x},)+) ($({ let x: $T = Default::default(); x},)+)