Skip to content

Commit

Permalink
Rollup merge of #102200 - ink-feather-org:const_default_impls, r=fee1…
Browse files Browse the repository at this point in the history
…-dead

Constify Default impl's for Arrays and Tuples.

Allows to create arrays and tuples in const Context using the ~const Default implementation of the inner type.
  • Loading branch information
fee1-dead authored Sep 25, 2022
2 parents b7d9de7 + 449326a commit 69aa41b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ impl<T: Copy> SpecArrayClone for T {
macro_rules! array_impl_default {
{$n:expr, $t:ident $($ts:ident)*} => {
#[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] {
[$t::default(), $($ts::default()),*]
}
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ macro_rules! tuple_impls {
maybe_tuple_doc! {
$($T)+ @
#[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]
fn default() -> ($($T,)+) {
($({ let x: $T = Default::default(); x},)+)
Expand Down

0 comments on commit 69aa41b

Please sign in to comment.