From 0a9c46319589a229da899fb550ee741d7ae3e5e7 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Mon, 7 Dec 2015 00:29:21 +0100 Subject: [PATCH 1/2] Revert "PR #30130 Implement `Clone` for more arrays" This reverts commit e22a64e8d8d4da46c74f878ce1c23ad1c88982e8. This caused a regression such that types like `[[u8; 256]; 4]` no longer implemented Clone. This previously worked due to Clone for `[T; N]` (N in 0 to 32) being implemented for T: Copy. Due to fixed size arrays not implementing Clone for sizes above 32, the new implementation requiring T: Clone would not allow `[[u8; 256]; 4]` to be Clone. --- src/libcore/array.rs | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/libcore/array.rs b/src/libcore/array.rs index 613ed0d14ee88..0c5eada21655c 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -27,7 +27,7 @@ use default::Default; use fmt; use hash::{Hash, self}; use iter::IntoIterator; -use marker::{Sized, Unsize}; +use marker::{Copy, Sized, Unsize}; use option::Option; use slice::{Iter, IterMut, SliceExt}; @@ -126,6 +126,13 @@ macro_rules! array_impls { } } + #[stable(feature = "rust1", since = "1.0.0")] + impl Clone for [T; $N] { + fn clone(&self) -> [T; $N] { + *self + } + } + #[stable(feature = "rust1", since = "1.0.0")] impl Hash for [T; $N] { fn hash(&self, state: &mut H) { @@ -235,30 +242,3 @@ macro_rules! array_impl_default { } 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} - -macro_rules! array_impl_clone { - {$n:expr, $i:expr, $($idx:expr,)*} => { - #[stable(feature = "rust1", since = "1.0.0")] - impl Clone for [T; $n] { - fn clone(&self) -> [T; $n] { - [self[$i-$i].clone(), $(self[$i-$idx].clone()),*] - } - } - array_impl_clone!{$i, $($idx,)*} - }; - {$n:expr,} => { - #[stable(feature = "rust1", since = "1.0.0")] - impl Clone for [T; 0] { - fn clone(&self) -> [T; 0] { - [] - } - } - }; -} - -array_impl_clone! { - 32, 31, 30, - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, - 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, - 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -} From 0ca2a9e71a9d907b79c3ca296163d313dc3234eb Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Mon, 7 Dec 2015 01:50:35 +0100 Subject: [PATCH 2/2] Add regression test for Clone for [[T; 256]; 4] where T: Copy and not Clone --- src/test/run-pass/deriving-clone-array.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/run-pass/deriving-clone-array.rs diff --git a/src/test/run-pass/deriving-clone-array.rs b/src/test/run-pass/deriving-clone-array.rs new file mode 100644 index 0000000000000..182a1390b1f75 --- /dev/null +++ b/src/test/run-pass/deriving-clone-array.rs @@ -0,0 +1,18 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// test for issue #30244 + +#[derive(Copy, Clone)] +struct Array { + arr: [[u8; 256]; 4] +} + +pub fn main() {}