Skip to content

Replace impl Copy fors with #[deriving(Copy)]s #19867

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

Merged
merged 23 commits into from
Dec 19, 2014
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
4 changes: 1 addition & 3 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
//! use std::collections::BinaryHeap;
//! use std::uint;
//!
//! #[deriving(Eq, PartialEq)]
//! #[deriving(Copy, Eq, PartialEq)]
//! struct State {
//! cost: uint,
//! position: uint
//! }
//!
//! impl Copy for State {}
//!
//! // The priority queue depends on `Ord`.
//! // Explicitly implement the trait so the queue becomes a min-heap
//! // instead of a max-heap.
Expand Down
7 changes: 2 additions & 5 deletions src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,12 @@ mod test {

use super::{EnumSet, CLike};

#[deriving(PartialEq, Show)]
#[deriving(Copy, PartialEq, Show)]
#[repr(uint)]
enum Foo {
A, B, C
}

impl Copy for Foo {}

impl CLike for Foo {
fn to_uint(&self) -> uint {
*self as uint
Expand Down Expand Up @@ -507,6 +505,7 @@ mod test {
#[should_fail]
fn test_overflow() {
#[allow(dead_code)]
#[deriving(Copy)]
#[repr(uint)]
enum Bar {
V00, V01, V02, V03, V04, V05, V06, V07, V08, V09,
Expand All @@ -518,8 +517,6 @@ mod test {
V60, V61, V62, V63, V64, V65, V66, V67, V68, V69,
}

impl Copy for Bar {}

impl CLike for Bar {
fn to_uint(&self) -> uint {
*self as uint
Expand Down
8 changes: 3 additions & 5 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ use alloc::boxed::Box;
use core::borrow::{BorrowFrom, BorrowFromMut, ToOwned};
use core::cmp;
use core::iter::{range_step, MultiplicativeIterator};
use core::kinds::{Copy, Sized};
use core::kinds::Sized;
use core::mem::size_of;
use core::mem;
use core::ops::FnMut;
Expand Down Expand Up @@ -177,18 +177,16 @@ impl ElementSwaps {
}
}

#[deriving(Copy)]
enum Direction { Pos, Neg }

impl Copy for Direction {}

/// An `Index` and `Direction` together.
#[deriving(Copy)]
struct SizeDirection {
size: uint,
dir: Direction,
}

impl Copy for SizeDirection {}

impl Iterator<(uint, uint)> for ElementSwaps {
#[inline]
fn next(&mut self) -> Option<(uint, uint)> {
Expand Down
4 changes: 1 addition & 3 deletions src/libcore/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub use self::Ordering::*;

use intrinsics;
use cell::UnsafeCell;
use kinds::Copy;

/// A boolean type which can be safely shared between threads.
#[stable]
Expand Down Expand Up @@ -53,6 +52,7 @@ pub struct AtomicPtr<T> {
/// Rust's memory orderings are [the same as
/// C++'s](http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync).
#[stable]
#[deriving(Copy)]
pub enum Ordering {
/// No ordering constraints, only atomic operations.
#[stable]
Expand All @@ -77,8 +77,6 @@ pub enum Ordering {
SeqCst,
}

impl Copy for Ordering {}

/// An `AtomicBool` initialized to `false`.
#[unstable = "may be renamed, pending conventions for static initalizers"]
pub const INIT_ATOMIC_BOOL: AtomicBool =
Expand Down
6 changes: 2 additions & 4 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

pub use self::Ordering::*;

use kinds::{Copy, Sized};
use kinds::Sized;
use option::Option::{mod, Some, None};

/// Trait for values that can be compared for equality and inequality.
Expand Down Expand Up @@ -94,7 +94,7 @@ pub trait Eq<Sized? Rhs = Self> for Sized?: PartialEq<Rhs> {
}

/// An ordering is, e.g, a result of a comparison between two values.
#[deriving(Clone, PartialEq, Show)]
#[deriving(Clone, Copy, PartialEq, Show)]
#[stable]
pub enum Ordering {
/// An ordering where a compared value is less [than another].
Expand All @@ -105,8 +105,6 @@ pub enum Ordering {
Greater = 1i,
}

impl Copy for Ordering {}

impl Ordering {
/// Reverse the `Ordering`, so that `Less` becomes `Greater` and
/// vice versa.
Expand Down
6 changes: 2 additions & 4 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ pub type Result = result::Result<(), Error>;
/// occurred. Any extra information must be arranged to be transmitted through
/// some other means.
#[experimental = "core and I/O reconciliation may alter this definition"]
#[deriving(Copy)]
pub struct Error;

impl Copy for Error {}

/// A collection of methods that are required to format a message into a stream.
///
/// This trait is the type which this modules requires when formatting
Expand Down Expand Up @@ -104,6 +103,7 @@ enum Void {}
/// compile time it is ensured that the function and the value have the correct
/// types, and then this struct is used to canonicalize arguments to one type.
#[experimental = "implementation detail of the `format_args!` macro"]
#[deriving(Copy)]
pub struct Argument<'a> {
value: &'a Void,
formatter: fn(&Void, &mut Formatter) -> Result,
Expand Down Expand Up @@ -137,8 +137,6 @@ impl<'a> Argument<'a> {
}
}

impl<'a> Copy for Argument<'a> {}

impl<'a> Arguments<'a> {
/// When using the format_args!() macro, this function is used to generate the
/// Arguments structure.
Expand Down
8 changes: 2 additions & 6 deletions src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use fmt;
use iter::DoubleEndedIteratorExt;
use kinds::Copy;
use num::{Int, cast};
use slice::SliceExt;

Expand Down Expand Up @@ -109,14 +108,12 @@ radix! { UpperHex, 16, "0x", x @ 0 ... 9 => b'0' + x,
x @ 10 ... 15 => b'A' + (x - 10) }

/// A radix with in the range of `2..36`.
#[deriving(Clone, PartialEq)]
#[deriving(Clone, Copy, PartialEq)]
#[unstable = "may be renamed or move to a different module"]
pub struct Radix {
base: u8,
}

impl Copy for Radix {}

impl Radix {
fn new(base: u8) -> Radix {
assert!(2 <= base && base <= 36, "the base must be in the range of 2..36: {}", base);
Expand All @@ -137,10 +134,9 @@ impl GenericRadix for Radix {

/// A helper type for formatting radixes.
#[unstable = "may be renamed or move to a different module"]
#[deriving(Copy)]
pub struct RadixFmt<T, R>(T, R);

impl<T,R> Copy for RadixFmt<T,R> where T: Copy, R: Copy {}

/// Constructs a radix formatter in the range of `2..36`.
///
/// # Example
Expand Down
20 changes: 6 additions & 14 deletions src/libcore/fmt/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ pub use self::Alignment::*;
pub use self::Count::*;
pub use self::Position::*;
pub use self::Flag::*;
use kinds::Copy;

#[doc(hidden)]
#[deriving(Copy)]
pub struct Argument<'a> {
pub position: Position,
pub format: FormatSpec,
}

impl<'a> Copy for Argument<'a> {}

#[doc(hidden)]
#[deriving(Copy)]
pub struct FormatSpec {
pub fill: char,
pub align: Alignment,
Expand All @@ -39,10 +38,8 @@ pub struct FormatSpec {
pub width: Count,
}

impl Copy for FormatSpec {}

/// Possible alignments that can be requested as part of a formatting directive.
#[deriving(PartialEq)]
#[deriving(Copy, PartialEq)]
pub enum Alignment {
/// Indication that contents should be left-aligned.
AlignLeft,
Expand All @@ -54,27 +51,24 @@ pub enum Alignment {
AlignUnknown,
}

impl Copy for Alignment {}

#[doc(hidden)]
#[deriving(Copy)]
pub enum Count {
CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied,
}

impl Copy for Count {}

#[doc(hidden)]
#[deriving(Copy)]
pub enum Position {
ArgumentNext, ArgumentIs(uint)
}

impl Copy for Position {}

/// Flags which can be passed to formatting via a directive.
///
/// These flags are discovered through the `flags` field of the `Formatter`
/// structure. The flag in that structure is a union of these flags into a
/// `uint` where each flag's discriminant is the corresponding bit.
#[deriving(Copy)]
pub enum Flag {
/// A flag which enables number formatting to always print the sign of a
/// number.
Expand All @@ -89,5 +83,3 @@ pub enum Flag {
/// being aware of the sign to be printed.
FlagSignAwareZeroPad,
}

impl Copy for Flag {}
3 changes: 1 addition & 2 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use default::Default;
use super::{Hash, Hasher, Writer};

/// `SipState` computes a SipHash 2-4 hash over a stream of bytes.
#[deriving(Copy)]
pub struct SipState {
k0: u64,
k1: u64,
Expand All @@ -42,8 +43,6 @@ pub struct SipState {
ntail: uint, // how many bytes in tail are valid
}

impl Copy for SipState {}

// sadly, these macro definitions can't appear later,
// because they're needed in the following defs;
// this design could be improved.
Expand Down
9 changes: 2 additions & 7 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@
#![experimental]
#![allow(missing_docs)]

use kinds::Copy;

pub type GlueFn = extern "Rust" fn(*const i8);

#[lang="ty_desc"]
#[deriving(Copy)]
pub struct TyDesc {
// sizeof(T)
pub size: uint,
Expand All @@ -61,8 +60,6 @@ pub struct TyDesc {
pub name: &'static str,
}

impl Copy for TyDesc {}

extern "rust-intrinsic" {

// NB: These intrinsics take unsafe pointers because they mutate aliased
Expand Down Expand Up @@ -540,13 +537,11 @@ extern "rust-intrinsic" {
/// `TypeId` represents a globally unique identifier for a type
#[lang="type_id"] // This needs to be kept in lockstep with the code in trans/intrinsic.rs and
// middle/lang_items.rs
#[deriving(Clone, PartialEq, Eq, Show)]
#[deriving(Clone, Copy, PartialEq, Eq, Show)]
pub struct TypeId {
t: u64,
}

impl Copy for TypeId {}

impl TypeId {
/// Returns the `TypeId` of the type this generic function has been instantiated with
pub fn of<T: 'static>() -> TypeId {
Expand Down
16 changes: 4 additions & 12 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub use self::MinMaxResult::*;
use clone::Clone;
use cmp;
use cmp::Ord;
use kinds::Copy;
use mem;
use num::{ToPrimitive, Int};
use ops::{Add, Deref, FnMut};
Expand Down Expand Up @@ -1168,16 +1167,14 @@ impl<A, I> CloneIteratorExt for I where I: Iterator<A> + Clone {
}

/// An iterator that repeats endlessly
#[deriving(Clone)]
#[deriving(Clone, Copy)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
#[stable]
pub struct Cycle<T> {
orig: T,
iter: T,
}

impl<T:Copy> Copy for Cycle<T> {}

impl<A, T: Clone + Iterator<A>> Iterator<A> for Cycle<T> {
#[inline]
fn next(&mut self) -> Option<A> {
Expand Down Expand Up @@ -1635,13 +1632,12 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<(uint, A)> for Enumerat
/// An iterator with a `peek()` that returns an optional reference to the next element.
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
#[stable]
#[deriving(Copy)]
pub struct Peekable<A, T> {
iter: T,
peeked: Option<A>,
}

impl<T:Copy,A:Copy> Copy for Peekable<A,T> {}

impl<A, T: Iterator<A>> Iterator<A> for Peekable<A, T> {
#[inline]
fn next(&mut self) -> Option<A> {
Expand Down Expand Up @@ -2267,7 +2263,7 @@ impl<A, St, F> Iterator<A> for Unfold<A, St, F> where F: FnMut(&mut St) -> Optio

/// An infinite iterator starting at `start` and advancing by `step` with each
/// iteration
#[deriving(Clone)]
#[deriving(Clone, Copy)]
#[unstable = "may be renamed"]
pub struct Counter<A> {
/// The current state the counter is at (next value to be yielded)
Expand All @@ -2276,8 +2272,6 @@ pub struct Counter<A> {
step: A,
}

impl<A:Copy> Copy for Counter<A> {}

/// Creates a new counter with the specified start/step
#[inline]
#[unstable = "may be renamed"]
Expand All @@ -2301,16 +2295,14 @@ impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
}

/// An iterator over the range [start, stop)
#[deriving(Clone)]
#[deriving(Clone, Copy)]
#[unstable = "may be refactored due to numerics reform or ops reform"]
pub struct Range<A> {
state: A,
stop: A,
one: A,
}

impl<A:Copy> Copy for Range<A> {}

/// Returns an iterator over the given range [start, stop) (that is, starting
/// at start (inclusive), and ending at stop (exclusive)).
///
Expand Down
Loading