Skip to content

Commit 7d4fadd

Browse files
committed
impl Copy/Clone for arrays in std, not in compiler
1 parent 7e2782e commit 7d4fadd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

core/src/array/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,24 @@ impl<T: Ord, const N: usize> Ord for [T; N] {
330330
}
331331
}
332332

333+
#[cfg(not(bootstrap))]
334+
#[stable(feature = "copy_clone_array_lib", since = "1.55.0")]
335+
impl<T: Copy, const N: usize> Copy for [T; N] {}
336+
337+
#[cfg(not(bootstrap))]
338+
#[stable(feature = "copy_clone_array_lib", since = "1.55.0")]
339+
impl<T: Clone, const N: usize> Clone for [T; N] {
340+
fn clone(&self) -> Self {
341+
// SAFETY: we know for certain that this iterator will yield exactly `N`
342+
// items.
343+
unsafe { collect_into_array_unchecked(&mut self.iter().cloned()) }
344+
}
345+
346+
fn clone_from(&mut self, other: &Self) {
347+
self.clone_from_slice(other);
348+
}
349+
}
350+
333351
// The Default impls cannot be done with const generics because `[T; 0]` doesn't
334352
// require Default to be implemented, and having different impl blocks for
335353
// different numbers isn't supported yet.

0 commit comments

Comments
 (0)