Skip to content

Commit e819d8a

Browse files
committed
Auto merge of #30247 - bluss:revert-array-clone, r=alexcrichton
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.
2 parents 64c21f9 + 0ca2a9e commit e819d8a

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

Diff for: src/libcore/array.rs

+8-28
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::{Sized, Unsize};
30+
use marker::{Copy, Sized, Unsize};
3131
use option::Option;
3232
use slice::{Iter, IterMut, SliceExt};
3333

@@ -126,6 +126,13 @@ macro_rules! array_impls {
126126
}
127127
}
128128

129+
#[stable(feature = "rust1", since = "1.0.0")]
130+
impl<T:Copy> Clone for [T; $N] {
131+
fn clone(&self) -> [T; $N] {
132+
*self
133+
}
134+
}
135+
129136
#[stable(feature = "rust1", since = "1.0.0")]
130137
impl<T: Hash> Hash for [T; $N] {
131138
fn hash<H: hash::Hasher>(&self, state: &mut H) {
@@ -235,30 +242,3 @@ macro_rules! array_impl_default {
235242
}
236243

237244
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}
238-
239-
macro_rules! array_impl_clone {
240-
{$n:expr, $i:expr, $($idx:expr,)*} => {
241-
#[stable(feature = "rust1", since = "1.0.0")]
242-
impl<T: Clone> Clone for [T; $n] {
243-
fn clone(&self) -> [T; $n] {
244-
[self[$i-$i].clone(), $(self[$i-$idx].clone()),*]
245-
}
246-
}
247-
array_impl_clone!{$i, $($idx,)*}
248-
};
249-
{$n:expr,} => {
250-
#[stable(feature = "rust1", since = "1.0.0")]
251-
impl<T: Clone> Clone for [T; 0] {
252-
fn clone(&self) -> [T; 0] {
253-
[]
254-
}
255-
}
256-
};
257-
}
258-
259-
array_impl_clone! {
260-
32, 31, 30,
261-
29, 28, 27, 26, 25, 24, 23, 22, 21, 20,
262-
19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
263-
9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
264-
}

Diff for: src/test/run-pass/deriving-clone-array.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// test for issue #30244
12+
13+
#[derive(Copy, Clone)]
14+
struct Array {
15+
arr: [[u8; 256]; 4]
16+
}
17+
18+
pub fn main() {}

0 commit comments

Comments
 (0)