Skip to content

Commit

Permalink
Auto merge of #30247 - bluss:revert-array-clone, r=alexcrichton
Browse files Browse the repository at this point in the history
Revert "PR #30130 Implement `Clone` for more arrays"

This reverts commit e22a64e.

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.

Fixes #30244

Due to changing back, this is technically a [breaking-change],
albeit for a behavior that existed for a very short time.
  • Loading branch information
bors committed Dec 7, 2015
2 parents 64c21f9 + 0ca2a9e commit e819d8a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
36 changes: 8 additions & 28 deletions src/libcore/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -126,6 +126,13 @@ macro_rules! array_impls {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Copy> Clone for [T; $N] {
fn clone(&self) -> [T; $N] {
*self
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Hash> Hash for [T; $N] {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
Expand Down Expand Up @@ -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<T: Clone> 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<T: Clone> 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,
}
18 changes: 18 additions & 0 deletions src/test/run-pass/deriving-clone-array.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}

0 comments on commit e819d8a

Please sign in to comment.