Skip to content

Commit

Permalink
rollup merge of rust-lang#23860: nikomatsakis/copy-requires-clone
Browse files Browse the repository at this point in the history
Conflicts:
	src/test/compile-fail/coherence-impls-copy.rs
  • Loading branch information
alexcrichton committed Apr 2, 2015
2 parents 05654e5 + 4496433 commit f92e7ab
Show file tree
Hide file tree
Showing 224 changed files with 624 additions and 583 deletions.
6 changes: 5 additions & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ specific type.
Implementations are defined with the keyword `impl`.

```
# #[derive(Copy)]
# #[derive(Copy, Clone)]
# struct Point {x: f64, y: f64};
# type Surface = i32;
# struct BoundingBox {x: f64, y: f64, width: f64, height: f64};
Expand All @@ -1661,6 +1661,10 @@ struct Circle {
impl Copy for Circle {}
impl Clone for Circle {
fn clone(&self) -> Circle { *self }
}
impl Shape for Circle {
fn draw(&self, s: Surface) { do_draw_circle(s, *self); }
fn bounding_box(&self) -> BoundingBox {
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//! use std::collections::BinaryHeap;
//! use std::usize;
//!
//! #[derive(Copy, Eq, PartialEq)]
//! #[derive(Copy, Clone, Eq, PartialEq)]
//! struct State {
//! cost: usize,
//! position: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl<K: Clone, V: Clone> Clone for Node<K, V> {
/// println!("Uninitialized memory: {:?}", handle.into_kv());
/// }
/// ```
#[derive(Copy)]
#[derive(Copy, Clone)]
pub struct Handle<NodeRef, Type, NodeType> {
node: NodeRef,
index: usize,
Expand Down
6 changes: 5 additions & 1 deletion src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use core::ops::{Sub, BitOr, BitAnd, BitXor};

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

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

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

impl<E> Clone for EnumSet<E> {
fn clone(&self) -> EnumSet<E> { *self }
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<E:CLike + fmt::Debug> fmt::Debug for EnumSet<E> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
Expand Down
4 changes: 2 additions & 2 deletions src/libcollectionstest/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use collections::enum_set::{CLike, EnumSet};

use self::Foo::*;

#[derive(Copy, PartialEq, Debug)]
#[derive(Copy, Clone, PartialEq, Debug)]
#[repr(usize)]
enum Foo {
A, B, C
Expand Down Expand Up @@ -218,7 +218,7 @@ fn test_operators() {
#[should_panic]
fn test_overflow() {
#[allow(dead_code)]
#[derive(Copy)]
#[derive(Copy, Clone)]
#[repr(usize)]
enum Bar {
V00, V01, V02, V03, V04, V05, V06, V07, V08, V09,
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
/// Rust's memory orderings are [the same as
/// C++'s](http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync).
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Copy)]
#[derive(Copy, Clone)]
pub enum Ordering {
/// No ordering constraints, only atomic operations.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
13 changes: 10 additions & 3 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

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

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

impl<'a> Clone for ArgumentV1<'a> {
fn clone(&self) -> ArgumentV1<'a> {
*self
}
}

impl<'a> ArgumentV1<'a> {
#[inline(never)]
fn show_usize(x: &usize, f: &mut Formatter) -> Result {
Expand Down Expand Up @@ -174,7 +181,7 @@ impl<'a> ArgumentV1<'a> {
}

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

Expand Down Expand Up @@ -221,7 +228,7 @@ impl<'a> Arguments<'a> {
/// macro validates the format string at compile-time so usage of the `write`
/// and `format` functions can be safely performed.
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Copy)]
#[derive(Copy, Clone)]
pub struct Arguments<'a> {
// Format string pieces to print.
pieces: &'a [&'a str],
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl GenericRadix for Radix {
/// A helper type for formatting radixes.
#[unstable(feature = "core",
reason = "may be renamed or move to a different module")]
#[derive(Copy)]
#[derive(Copy, Clone)]
pub struct RadixFmt<T, R>(T, R);

/// Constructs a radix formatter in the range of `2..36`.
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/fmt/rt/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#![stable(feature = "rust1", since = "1.0.0")]

#[derive(Copy)]
#[derive(Copy, Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Argument {
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -25,7 +25,7 @@ pub struct Argument {
pub format: FormatSpec,
}

#[derive(Copy)]
#[derive(Copy, Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct FormatSpec {
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -41,7 +41,7 @@ pub struct FormatSpec {
}

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

#[derive(Copy)]
#[derive(Copy, Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Count {
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -71,7 +71,7 @@ pub enum Count {
Implied,
}

#[derive(Copy)]
#[derive(Copy, Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Position {
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
7 changes: 4 additions & 3 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub trait Sized : MarkerTrait {
///
/// ```
/// // we can just derive a `Copy` implementation
/// #[derive(Debug, Copy)]
/// #[derive(Debug, Copy, Clone)]
/// struct Foo;
///
/// let x = Foo;
Expand Down Expand Up @@ -125,7 +125,7 @@ pub trait Sized : MarkerTrait {
/// There are two ways to implement `Copy` on your type:
///
/// ```
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct MyStruct;
/// ```
///
Expand All @@ -134,6 +134,7 @@ pub trait Sized : MarkerTrait {
/// ```
/// struct MyStruct;
/// impl Copy for MyStruct {}
/// impl Clone for MyStruct { fn clone(&self) -> MyStruct { *self } }
/// ```
///
/// There is a small difference between the two: the `derive` strategy will also place a `Copy`
Expand All @@ -155,7 +156,7 @@ pub trait Sized : MarkerTrait {
/// change: that second example would fail to compile if we made `Foo` non-`Copy`.
#[stable(feature = "rust1", since = "1.0.0")]
#[lang="copy"]
pub trait Copy : MarkerTrait {
pub trait Copy : Clone {
// Empty.
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,7 @@ impl_num_cast! { f32, to_f32 }
impl_num_cast! { f64, to_f64 }

/// Used for representing the classification of floating point numbers
#[derive(Copy, PartialEq, Debug)]
#[derive(Copy, Clone, PartialEq, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum FpCategory {
/// "Not a Number", often obtained by dividing by zero
Expand Down
28 changes: 14 additions & 14 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ macro_rules! forward_ref_binop {
/// ```
/// use std::ops::Add;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Add for Foo {
Expand Down Expand Up @@ -219,7 +219,7 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
/// ```
/// use std::ops::Sub;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Sub for Foo {
Expand Down Expand Up @@ -273,7 +273,7 @@ sub_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
/// ```
/// use std::ops::Mul;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Mul for Foo {
Expand Down Expand Up @@ -327,7 +327,7 @@ mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
/// ```
/// use std::ops::Div;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Div for Foo {
Expand Down Expand Up @@ -381,7 +381,7 @@ div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
/// ```
/// use std::ops::Rem;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Rem for Foo {
Expand Down Expand Up @@ -454,7 +454,7 @@ rem_float_impl! { f64, fmod }
/// ```
/// use std::ops::Neg;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Neg for Foo {
Expand Down Expand Up @@ -527,7 +527,7 @@ neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 }
/// ```
/// use std::ops::Not;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Not for Foo {
Expand Down Expand Up @@ -581,7 +581,7 @@ not_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
/// ```
/// use std::ops::BitAnd;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl BitAnd for Foo {
Expand Down Expand Up @@ -635,7 +635,7 @@ bitand_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
/// ```
/// use std::ops::BitOr;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl BitOr for Foo {
Expand Down Expand Up @@ -689,7 +689,7 @@ bitor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
/// ```
/// use std::ops::BitXor;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl BitXor for Foo {
Expand Down Expand Up @@ -743,7 +743,7 @@ bitxor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
/// ```
/// use std::ops::Shl;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Shl<Foo> for Foo {
Expand Down Expand Up @@ -815,7 +815,7 @@ shl_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
/// ```
/// use std::ops::Shr;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
///
/// impl Shr<Foo> for Foo {
Expand Down Expand Up @@ -887,7 +887,7 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
/// ```
/// use std::ops::Index;
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
/// struct Bar;
///
Expand Down Expand Up @@ -928,7 +928,7 @@ pub trait Index<Idx: ?Sized> {
/// ```
/// use std::ops::{Index, IndexMut};
///
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct Foo;
/// struct Bar;
///
Expand Down
6 changes: 5 additions & 1 deletion src/libcore/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//!
//! Their definition should always match the ABI defined in `rustc::back::abi`.

use clone::Clone;
use marker::Copy;
use mem;

Expand Down Expand Up @@ -63,6 +64,9 @@ pub struct Slice<T> {
}

impl<T> Copy for Slice<T> {}
impl<T> Clone for Slice<T> {
fn clone(&self) -> Slice<T> { *self }
}

/// The representation of a trait object like `&SomeTrait`.
///
Expand Down Expand Up @@ -136,7 +140,7 @@ impl<T> Copy for Slice<T> {}
/// assert_eq!(synthesized.bar(), 457);
/// ```
#[repr(C)]
#[derive(Copy)]
#[derive(Copy, Clone)]
pub struct TraitObject {
pub data: *mut (),
pub vtable: *mut (),
Expand Down
Loading

0 comments on commit f92e7ab

Please sign in to comment.