Skip to content

Commit bfa075c

Browse files
committed
not bootstrap
1 parent 5353301 commit bfa075c

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

library/core/src/array/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ impl<T: Ord, const N: usize> Ord for [T; N] {
354354
}
355355

356356
/// This module implements `Default` for arrays.
357+
#[cfg(not(bootstrap))]
357358
mod default_impls {
358359
// A trait implemented by all arrays which are either empty or contain a type implementing `Default`.
359360
#[unstable(
@@ -399,14 +400,37 @@ mod default_impls {
399400
[T; N]: ArrayDefault,
400401
{
401402
fn default() -> [T; N] {
402-
assert_eq!(std::mem::size_of::<[(); N]>(), 0);
403+
assert_eq!(crate::mem::size_of::<[(); N]>(), 0);
403404
// SAFETY: it is always valid to use `zeroed` for zero-sized value.
404-
let arr: [(); N] = unsafe { std::mem::zeroed() };
405+
let arr: [(); N] = unsafe { crate::mem::zeroed() };
405406
arr.map(|_unit| DefaultHack::default_hack())
406407
}
407408
}
408409
}
409410

411+
#[cfg(bootstrap)]
412+
mod default_impls {
413+
macro_rules! array_impl_default {
414+
{$n:expr, $t:ident $($ts:ident)*} => {
415+
#[stable(since = "1.4.0", feature = "array_default")]
416+
impl<T> Default for [T; $n] where T: Default {
417+
fn default() -> [T; $n] {
418+
[$t::default(), $($ts::default()),*]
419+
}
420+
}
421+
array_impl_default!{($n - 1), $($ts)*}
422+
};
423+
{$n:expr,} => {
424+
#[stable(since = "1.4.0", feature = "array_default")]
425+
impl<T> Default for [T; $n] {
426+
fn default() -> [T; $n] { [] }
427+
}
428+
};
429+
}
430+
431+
array_impl_default! {16, T T T T T T T T T T T T T T T T}
432+
}
433+
410434

411435
#[lang = "array"]
412436
impl<T, const N: usize> [T; N] {

library/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#![allow(explicit_outlives_requirements)]
6565
#![allow(incomplete_features)]
6666
#![feature(allow_internal_unstable)]
67-
#![feature(array_default_internals)]
67+
#![cfg_attr(not(bootstrap), feature(array_default_internals))]
6868
#![feature(arbitrary_self_types)]
6969
#![feature(asm)]
7070
#![feature(cfg_target_has_atomic)]

0 commit comments

Comments
 (0)