Skip to content

Commit f92e7ab

Browse files
committed
rollup merge of rust-lang#23860: nikomatsakis/copy-requires-clone
Conflicts: src/test/compile-fail/coherence-impls-copy.rs
2 parents 05654e5 + 4496433 commit f92e7ab

File tree

224 files changed

+624
-583
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+624
-583
lines changed

src/doc/reference.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ specific type.
16481648
Implementations are defined with the keyword `impl`.
16491649

16501650
```
1651-
# #[derive(Copy)]
1651+
# #[derive(Copy, Clone)]
16521652
# struct Point {x: f64, y: f64};
16531653
# type Surface = i32;
16541654
# struct BoundingBox {x: f64, y: f64, width: f64, height: f64};
@@ -1661,6 +1661,10 @@ struct Circle {
16611661
16621662
impl Copy for Circle {}
16631663
1664+
impl Clone for Circle {
1665+
fn clone(&self) -> Circle { *self }
1666+
}
1667+
16641668
impl Shape for Circle {
16651669
fn draw(&self, s: Surface) { do_draw_circle(s, *self); }
16661670
fn bounding_box(&self) -> BoundingBox {

src/libcollections/binary_heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//! use std::collections::BinaryHeap;
3131
//! use std::usize;
3232
//!
33-
//! #[derive(Copy, Eq, PartialEq)]
33+
//! #[derive(Copy, Clone, Eq, PartialEq)]
3434
//! struct State {
3535
//! cost: usize,
3636
//! position: usize,

src/libcollections/btree/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl<K: Clone, V: Clone> Clone for Node<K, V> {
526526
/// println!("Uninitialized memory: {:?}", handle.into_kv());
527527
/// }
528528
/// ```
529-
#[derive(Copy)]
529+
#[derive(Copy, Clone)]
530530
pub struct Handle<NodeRef, Type, NodeType> {
531531
node: NodeRef,
532532
index: usize,

src/libcollections/enum_set.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use core::ops::{Sub, BitOr, BitAnd, BitXor};
2121

2222
// FIXME(contentions): implement union family of methods? (general design may be wrong here)
2323

24-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
24+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
2525
/// A specialized set implementation to use enum types.
2626
///
2727
/// It is a logic error for an item to be modified in such a way that the transformation of the
@@ -37,6 +37,10 @@ pub struct EnumSet<E> {
3737

3838
impl<E> Copy for EnumSet<E> {}
3939

40+
impl<E> Clone for EnumSet<E> {
41+
fn clone(&self) -> EnumSet<E> { *self }
42+
}
43+
4044
#[stable(feature = "rust1", since = "1.0.0")]
4145
impl<E:CLike + fmt::Debug> fmt::Debug for EnumSet<E> {
4246
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {

src/libcollectionstest/enum_set.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use collections::enum_set::{CLike, EnumSet};
1414

1515
use self::Foo::*;
1616

17-
#[derive(Copy, PartialEq, Debug)]
17+
#[derive(Copy, Clone, PartialEq, Debug)]
1818
#[repr(usize)]
1919
enum Foo {
2020
A, B, C
@@ -218,7 +218,7 @@ fn test_operators() {
218218
#[should_panic]
219219
fn test_overflow() {
220220
#[allow(dead_code)]
221-
#[derive(Copy)]
221+
#[derive(Copy, Clone)]
222222
#[repr(usize)]
223223
enum Bar {
224224
V00, V01, V02, V03, V04, V05, V06, V07, V08, V09,

src/libcore/atomic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
122122
/// Rust's memory orderings are [the same as
123123
/// C++'s](http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync).
124124
#[stable(feature = "rust1", since = "1.0.0")]
125-
#[derive(Copy)]
125+
#[derive(Copy, Clone)]
126126
pub enum Ordering {
127127
/// No ordering constraints, only atomic operations.
128128
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/fmt/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use cell::{Cell, RefCell, Ref, RefMut, BorrowState};
1616
use char::CharExt;
17+
use clone::Clone;
1718
use iter::Iterator;
1819
use marker::{Copy, PhantomData, Sized};
1920
use mem;
@@ -53,7 +54,7 @@ pub type Result = result::Result<(), Error>;
5354
/// occurred. Any extra information must be arranged to be transmitted through
5455
/// some other means.
5556
#[stable(feature = "rust1", since = "1.0.0")]
56-
#[derive(Copy, Debug)]
57+
#[derive(Copy, Clone, Debug)]
5758
pub struct Error;
5859

5960
/// A collection of methods that are required to format a message into a stream.
@@ -140,6 +141,12 @@ pub struct ArgumentV1<'a> {
140141
formatter: fn(&Void, &mut Formatter) -> Result,
141142
}
142143

144+
impl<'a> Clone for ArgumentV1<'a> {
145+
fn clone(&self) -> ArgumentV1<'a> {
146+
*self
147+
}
148+
}
149+
143150
impl<'a> ArgumentV1<'a> {
144151
#[inline(never)]
145152
fn show_usize(x: &usize, f: &mut Formatter) -> Result {
@@ -174,7 +181,7 @@ impl<'a> ArgumentV1<'a> {
174181
}
175182

176183
// flags available in the v1 format of format_args
177-
#[derive(Copy)]
184+
#[derive(Copy, Clone)]
178185
#[allow(dead_code)] // SignMinus isn't currently used
179186
enum FlagV1 { SignPlus, SignMinus, Alternate, SignAwareZeroPad, }
180187

@@ -221,7 +228,7 @@ impl<'a> Arguments<'a> {
221228
/// macro validates the format string at compile-time so usage of the `write`
222229
/// and `format` functions can be safely performed.
223230
#[stable(feature = "rust1", since = "1.0.0")]
224-
#[derive(Copy)]
231+
#[derive(Copy, Clone)]
225232
pub struct Arguments<'a> {
226233
// Format string pieces to print.
227234
pieces: &'a [&'a str],

src/libcore/fmt/num.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl GenericRadix for Radix {
139139
/// A helper type for formatting radixes.
140140
#[unstable(feature = "core",
141141
reason = "may be renamed or move to a different module")]
142-
#[derive(Copy)]
142+
#[derive(Copy, Clone)]
143143
pub struct RadixFmt<T, R>(T, R);
144144

145145
/// Constructs a radix formatter in the range of `2..36`.

src/libcore/fmt/rt/v1.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
#![stable(feature = "rust1", since = "1.0.0")]
1818

19-
#[derive(Copy)]
19+
#[derive(Copy, Clone)]
2020
#[stable(feature = "rust1", since = "1.0.0")]
2121
pub struct Argument {
2222
#[stable(feature = "rust1", since = "1.0.0")]
@@ -25,7 +25,7 @@ pub struct Argument {
2525
pub format: FormatSpec,
2626
}
2727

28-
#[derive(Copy)]
28+
#[derive(Copy, Clone)]
2929
#[stable(feature = "rust1", since = "1.0.0")]
3030
pub struct FormatSpec {
3131
#[stable(feature = "rust1", since = "1.0.0")]
@@ -41,7 +41,7 @@ pub struct FormatSpec {
4141
}
4242

4343
/// Possible alignments that can be requested as part of a formatting directive.
44-
#[derive(Copy, PartialEq)]
44+
#[derive(Copy, Clone, PartialEq)]
4545
#[stable(feature = "rust1", since = "1.0.0")]
4646
pub enum Alignment {
4747
/// Indication that contents should be left-aligned.
@@ -58,7 +58,7 @@ pub enum Alignment {
5858
Unknown,
5959
}
6060

61-
#[derive(Copy)]
61+
#[derive(Copy, Clone)]
6262
#[stable(feature = "rust1", since = "1.0.0")]
6363
pub enum Count {
6464
#[stable(feature = "rust1", since = "1.0.0")]
@@ -71,7 +71,7 @@ pub enum Count {
7171
Implied,
7272
}
7373

74-
#[derive(Copy)]
74+
#[derive(Copy, Clone)]
7575
#[stable(feature = "rust1", since = "1.0.0")]
7676
pub enum Position {
7777
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/marker.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub trait Sized : MarkerTrait {
7676
///
7777
/// ```
7878
/// // we can just derive a `Copy` implementation
79-
/// #[derive(Debug, Copy)]
79+
/// #[derive(Debug, Copy, Clone)]
8080
/// struct Foo;
8181
///
8282
/// let x = Foo;
@@ -125,7 +125,7 @@ pub trait Sized : MarkerTrait {
125125
/// There are two ways to implement `Copy` on your type:
126126
///
127127
/// ```
128-
/// #[derive(Copy)]
128+
/// #[derive(Copy, Clone)]
129129
/// struct MyStruct;
130130
/// ```
131131
///
@@ -134,6 +134,7 @@ pub trait Sized : MarkerTrait {
134134
/// ```
135135
/// struct MyStruct;
136136
/// impl Copy for MyStruct {}
137+
/// impl Clone for MyStruct { fn clone(&self) -> MyStruct { *self } }
137138
/// ```
138139
///
139140
/// There is a small difference between the two: the `derive` strategy will also place a `Copy`
@@ -155,7 +156,7 @@ pub trait Sized : MarkerTrait {
155156
/// change: that second example would fail to compile if we made `Foo` non-`Copy`.
156157
#[stable(feature = "rust1", since = "1.0.0")]
157158
#[lang="copy"]
158-
pub trait Copy : MarkerTrait {
159+
pub trait Copy : Clone {
159160
// Empty.
160161
}
161162

src/libcore/num/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2444,7 +2444,7 @@ impl_num_cast! { f32, to_f32 }
24442444
impl_num_cast! { f64, to_f64 }
24452445

24462446
/// Used for representing the classification of floating point numbers
2447-
#[derive(Copy, PartialEq, Debug)]
2447+
#[derive(Copy, Clone, PartialEq, Debug)]
24482448
#[stable(feature = "rust1", since = "1.0.0")]
24492449
pub enum FpCategory {
24502450
/// "Not a Number", often obtained by dividing by zero

src/libcore/ops.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ macro_rules! forward_ref_binop {
165165
/// ```
166166
/// use std::ops::Add;
167167
///
168-
/// #[derive(Copy)]
168+
/// #[derive(Copy, Clone)]
169169
/// struct Foo;
170170
///
171171
/// impl Add for Foo {
@@ -219,7 +219,7 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
219219
/// ```
220220
/// use std::ops::Sub;
221221
///
222-
/// #[derive(Copy)]
222+
/// #[derive(Copy, Clone)]
223223
/// struct Foo;
224224
///
225225
/// impl Sub for Foo {
@@ -273,7 +273,7 @@ sub_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
273273
/// ```
274274
/// use std::ops::Mul;
275275
///
276-
/// #[derive(Copy)]
276+
/// #[derive(Copy, Clone)]
277277
/// struct Foo;
278278
///
279279
/// impl Mul for Foo {
@@ -327,7 +327,7 @@ mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
327327
/// ```
328328
/// use std::ops::Div;
329329
///
330-
/// #[derive(Copy)]
330+
/// #[derive(Copy, Clone)]
331331
/// struct Foo;
332332
///
333333
/// impl Div for Foo {
@@ -381,7 +381,7 @@ div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
381381
/// ```
382382
/// use std::ops::Rem;
383383
///
384-
/// #[derive(Copy)]
384+
/// #[derive(Copy, Clone)]
385385
/// struct Foo;
386386
///
387387
/// impl Rem for Foo {
@@ -454,7 +454,7 @@ rem_float_impl! { f64, fmod }
454454
/// ```
455455
/// use std::ops::Neg;
456456
///
457-
/// #[derive(Copy)]
457+
/// #[derive(Copy, Clone)]
458458
/// struct Foo;
459459
///
460460
/// impl Neg for Foo {
@@ -527,7 +527,7 @@ neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 }
527527
/// ```
528528
/// use std::ops::Not;
529529
///
530-
/// #[derive(Copy)]
530+
/// #[derive(Copy, Clone)]
531531
/// struct Foo;
532532
///
533533
/// impl Not for Foo {
@@ -581,7 +581,7 @@ not_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
581581
/// ```
582582
/// use std::ops::BitAnd;
583583
///
584-
/// #[derive(Copy)]
584+
/// #[derive(Copy, Clone)]
585585
/// struct Foo;
586586
///
587587
/// impl BitAnd for Foo {
@@ -635,7 +635,7 @@ bitand_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
635635
/// ```
636636
/// use std::ops::BitOr;
637637
///
638-
/// #[derive(Copy)]
638+
/// #[derive(Copy, Clone)]
639639
/// struct Foo;
640640
///
641641
/// impl BitOr for Foo {
@@ -689,7 +689,7 @@ bitor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
689689
/// ```
690690
/// use std::ops::BitXor;
691691
///
692-
/// #[derive(Copy)]
692+
/// #[derive(Copy, Clone)]
693693
/// struct Foo;
694694
///
695695
/// impl BitXor for Foo {
@@ -743,7 +743,7 @@ bitxor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
743743
/// ```
744744
/// use std::ops::Shl;
745745
///
746-
/// #[derive(Copy)]
746+
/// #[derive(Copy, Clone)]
747747
/// struct Foo;
748748
///
749749
/// impl Shl<Foo> for Foo {
@@ -815,7 +815,7 @@ shl_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
815815
/// ```
816816
/// use std::ops::Shr;
817817
///
818-
/// #[derive(Copy)]
818+
/// #[derive(Copy, Clone)]
819819
/// struct Foo;
820820
///
821821
/// impl Shr<Foo> for Foo {
@@ -887,7 +887,7 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
887887
/// ```
888888
/// use std::ops::Index;
889889
///
890-
/// #[derive(Copy)]
890+
/// #[derive(Copy, Clone)]
891891
/// struct Foo;
892892
/// struct Bar;
893893
///
@@ -928,7 +928,7 @@ pub trait Index<Idx: ?Sized> {
928928
/// ```
929929
/// use std::ops::{Index, IndexMut};
930930
///
931-
/// #[derive(Copy)]
931+
/// #[derive(Copy, Clone)]
932932
/// struct Foo;
933933
/// struct Bar;
934934
///

src/libcore/raw.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
//!
1919
//! Their definition should always match the ABI defined in `rustc::back::abi`.
2020
21+
use clone::Clone;
2122
use marker::Copy;
2223
use mem;
2324

@@ -63,6 +64,9 @@ pub struct Slice<T> {
6364
}
6465

6566
impl<T> Copy for Slice<T> {}
67+
impl<T> Clone for Slice<T> {
68+
fn clone(&self) -> Slice<T> { *self }
69+
}
6670

6771
/// The representation of a trait object like `&SomeTrait`.
6872
///
@@ -136,7 +140,7 @@ impl<T> Copy for Slice<T> {}
136140
/// assert_eq!(synthesized.bar(), 457);
137141
/// ```
138142
#[repr(C)]
139-
#[derive(Copy)]
143+
#[derive(Copy, Clone)]
140144
pub struct TraitObject {
141145
pub data: *mut (),
142146
pub vtable: *mut (),

0 commit comments

Comments
 (0)