Skip to content

Commit 19b9ad7

Browse files
committed
Implement Clone for [T; 0] to [T; 32] if T: Clone
1 parent 4f6fe3e commit 19b9ad7

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/libcore/array.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use default::Default;
2727
use fmt;
2828
use hash::{Hash, self};
2929
use iter::IntoIterator;
30-
use marker::{Copy, Sized, Unsize};
30+
use marker::{Sized, Unsize};
3131
use option::Option;
3232
use slice::{Iter, IterMut, SliceExt};
3333

@@ -94,13 +94,6 @@ macro_rules! array_impls {
9494
}
9595
}
9696

97-
#[stable(feature = "rust1", since = "1.0.0")]
98-
impl<T:Copy> Clone for [T; $N] {
99-
fn clone(&self) -> [T; $N] {
100-
*self
101-
}
102-
}
103-
10497
#[stable(feature = "rust1", since = "1.0.0")]
10598
impl<T: Hash> Hash for [T; $N] {
10699
fn hash<H: hash::Hasher>(&self, state: &mut H) {
@@ -210,3 +203,31 @@ macro_rules! array_impl_default {
210203
}
211204

212205
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}
206+
207+
macro_rules! array_impl_clone {
208+
{$n:expr, $t:ident $($ts:ident)*} => {
209+
#[stable(feature = "rust1", since = "1.0.0")]
210+
impl<T: Clone> Clone for [T; $n] {
211+
fn clone(&self) -> [T; $n] {
212+
let &[ref $t, $(ref $ts),*] = self;
213+
[$t.clone(), $($ts.clone()),*]
214+
}
215+
}
216+
array_impl_clone!{($n - 1), $($ts)*}
217+
};
218+
{$n:expr,} => {
219+
#[stable(feature = "rust1", since = "1.0.0")]
220+
impl<T: Clone> Clone for [T; 0] {
221+
fn clone(&self) -> [T; 0] {
222+
[]
223+
}
224+
}
225+
};
226+
}
227+
228+
array_impl_clone! { 32,
229+
t00 t01 t02 t03 t04 t05 t06 t07 t08 t09
230+
t10 t11 t12 t13 t14 t15 t16 t17 t18 t19
231+
t20 t21 t22 t23 t24 t25 t26 t27 t28 t29
232+
t30 t31
233+
}

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#![feature(unwind_attributes)]
8686
#![cfg_attr(stage0, feature(simd))]
8787
#![cfg_attr(not(stage0), feature(repr_simd, platform_intrinsics))]
88+
#![feature(slice_patterns)]
8889
#![feature(staged_api)]
8990
#![feature(unboxed_closures)]
9091

0 commit comments

Comments
 (0)