Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Copy a subtrait of Clone #23860

Merged
merged 7 commits into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -15,6 +15,7 @@
use any;
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 @@ -54,7 +55,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 @@ -141,6 +142,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 @@ -175,7 +182,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 @@ -222,7 +229,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 @@ -75,7 +75,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 @@ -124,7 +124,7 @@ pub trait Sized : MarkerTrait {
/// There are two ways to implement `Copy` on your type:
///
/// ```
/// #[derive(Copy)]
/// #[derive(Copy, Clone)]
/// struct MyStruct;
/// ```
///
Expand All @@ -133,6 +133,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 @@ -154,7 +155,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 @@ -2425,7 +2425,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 @@ -511,7 +511,7 @@ neg_impl! { usize u8 u16 u32 u64 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 @@ -565,7 +565,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 @@ -619,7 +619,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 @@ -673,7 +673,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 @@ -727,7 +727,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 @@ -799,7 +799,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 @@ -871,7 +871,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 @@ -912,7 +912,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