Skip to content

Commit 95c2ed3

Browse files
committed
auto merge of #19867 : japaric/rust/deriving-copy, r=acrichto
r? @alexcrichton
2 parents bd90b93 + f975b10 commit 95c2ed3

File tree

147 files changed

+484
-1267
lines changed

Some content is hidden

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

147 files changed

+484
-1267
lines changed

src/libcollections/binary_heap.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@
2929
//! use std::collections::BinaryHeap;
3030
//! use std::uint;
3131
//!
32-
//! #[deriving(Eq, PartialEq)]
32+
//! #[deriving(Copy, Eq, PartialEq)]
3333
//! struct State {
3434
//! cost: uint,
3535
//! position: uint
3636
//! }
3737
//!
38-
//! impl Copy for State {}
39-
//!
4038
//! // The priority queue depends on `Ord`.
4139
//! // Explicitly implement the trait so the queue becomes a min-heap
4240
//! // instead of a max-heap.

src/libcollections/enum_set.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,12 @@ mod test {
301301

302302
use super::{EnumSet, CLike};
303303

304-
#[deriving(PartialEq, Show)]
304+
#[deriving(Copy, PartialEq, Show)]
305305
#[repr(uint)]
306306
enum Foo {
307307
A, B, C
308308
}
309309

310-
impl Copy for Foo {}
311-
312310
impl CLike for Foo {
313311
fn to_uint(&self) -> uint {
314312
*self as uint
@@ -507,6 +505,7 @@ mod test {
507505
#[should_fail]
508506
fn test_overflow() {
509507
#[allow(dead_code)]
508+
#[deriving(Copy)]
510509
#[repr(uint)]
511510
enum Bar {
512511
V00, V01, V02, V03, V04, V05, V06, V07, V08, V09,
@@ -518,8 +517,6 @@ mod test {
518517
V60, V61, V62, V63, V64, V65, V66, V67, V68, V69,
519518
}
520519

521-
impl Copy for Bar {}
522-
523520
impl CLike for Bar {
524521
fn to_uint(&self) -> uint {
525522
*self as uint

src/libcollections/slice.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ use alloc::boxed::Box;
9191
use core::borrow::{BorrowFrom, BorrowFromMut, ToOwned};
9292
use core::cmp;
9393
use core::iter::{range_step, MultiplicativeIterator};
94-
use core::kinds::{Copy, Sized};
94+
use core::kinds::Sized;
9595
use core::mem::size_of;
9696
use core::mem;
9797
use core::ops::FnMut;
@@ -177,18 +177,16 @@ impl ElementSwaps {
177177
}
178178
}
179179

180+
#[deriving(Copy)]
180181
enum Direction { Pos, Neg }
181182

182-
impl Copy for Direction {}
183-
184183
/// An `Index` and `Direction` together.
184+
#[deriving(Copy)]
185185
struct SizeDirection {
186186
size: uint,
187187
dir: Direction,
188188
}
189189

190-
impl Copy for SizeDirection {}
191-
192190
impl Iterator<(uint, uint)> for ElementSwaps {
193191
#[inline]
194192
fn next(&mut self) -> Option<(uint, uint)> {

src/libcore/atomic.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub use self::Ordering::*;
1616

1717
use intrinsics;
1818
use cell::UnsafeCell;
19-
use kinds::Copy;
2019

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

80-
impl Copy for Ordering {}
81-
8280
/// An `AtomicBool` initialized to `false`.
8381
#[unstable = "may be renamed, pending conventions for static initalizers"]
8482
pub const INIT_ATOMIC_BOOL: AtomicBool =

src/libcore/cmp.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
pub use self::Ordering::*;
4545

46-
use kinds::{Copy, Sized};
46+
use kinds::Sized;
4747
use option::Option::{mod, Some, None};
4848

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

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

108-
impl Copy for Ordering {}
109-
110108
impl Ordering {
111109
/// Reverse the `Ordering`, so that `Less` becomes `Greater` and
112110
/// vice versa.

src/libcore/fmt/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ pub type Result = result::Result<(), Error>;
4444
/// occurred. Any extra information must be arranged to be transmitted through
4545
/// some other means.
4646
#[experimental = "core and I/O reconciliation may alter this definition"]
47+
#[deriving(Copy)]
4748
pub struct Error;
4849

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

140-
impl<'a> Copy for Argument<'a> {}
141-
142140
impl<'a> Arguments<'a> {
143141
/// When using the format_args!() macro, this function is used to generate the
144142
/// Arguments structure.

src/libcore/fmt/num.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
use fmt;
1818
use iter::DoubleEndedIteratorExt;
19-
use kinds::Copy;
2019
use num::{Int, cast};
2120
use slice::SliceExt;
2221

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

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

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

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

142-
impl<T,R> Copy for RadixFmt<T,R> where T: Copy, R: Copy {}
143-
144140
/// Constructs a radix formatter in the range of `2..36`.
145141
///
146142
/// # Example

src/libcore/fmt/rt.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ pub use self::Alignment::*;
2020
pub use self::Count::*;
2121
pub use self::Position::*;
2222
pub use self::Flag::*;
23-
use kinds::Copy;
2423

2524
#[doc(hidden)]
25+
#[deriving(Copy)]
2626
pub struct Argument<'a> {
2727
pub position: Position,
2828
pub format: FormatSpec,
2929
}
3030

31-
impl<'a> Copy for Argument<'a> {}
32-
3331
#[doc(hidden)]
32+
#[deriving(Copy)]
3433
pub struct FormatSpec {
3534
pub fill: char,
3635
pub align: Alignment,
@@ -39,10 +38,8 @@ pub struct FormatSpec {
3938
pub width: Count,
4039
}
4140

42-
impl Copy for FormatSpec {}
43-
4441
/// Possible alignments that can be requested as part of a formatting directive.
45-
#[deriving(PartialEq)]
42+
#[deriving(Copy, PartialEq)]
4643
pub enum Alignment {
4744
/// Indication that contents should be left-aligned.
4845
AlignLeft,
@@ -54,27 +51,24 @@ pub enum Alignment {
5451
AlignUnknown,
5552
}
5653

57-
impl Copy for Alignment {}
58-
5954
#[doc(hidden)]
55+
#[deriving(Copy)]
6056
pub enum Count {
6157
CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied,
6258
}
6359

64-
impl Copy for Count {}
65-
6660
#[doc(hidden)]
61+
#[deriving(Copy)]
6762
pub enum Position {
6863
ArgumentNext, ArgumentIs(uint)
6964
}
7065

71-
impl Copy for Position {}
72-
7366
/// Flags which can be passed to formatting via a directive.
7467
///
7568
/// These flags are discovered through the `flags` field of the `Formatter`
7669
/// structure. The flag in that structure is a union of these flags into a
7770
/// `uint` where each flag's discriminant is the corresponding bit.
71+
#[deriving(Copy)]
7872
pub enum Flag {
7973
/// A flag which enables number formatting to always print the sign of a
8074
/// number.
@@ -89,5 +83,3 @@ pub enum Flag {
8983
/// being aware of the sign to be printed.
9084
FlagSignAwareZeroPad,
9185
}
92-
93-
impl Copy for Flag {}

src/libcore/hash/sip.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use default::Default;
3030
use super::{Hash, Hasher, Writer};
3131

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

45-
impl Copy for SipState {}
46-
4746
// sadly, these macro definitions can't appear later,
4847
// because they're needed in the following defs;
4948
// this design could be improved.

src/libcore/intrinsics.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@
4242
#![experimental]
4343
#![allow(missing_docs)]
4444

45-
use kinds::Copy;
46-
4745
pub type GlueFn = extern "Rust" fn(*const i8);
4846

4947
#[lang="ty_desc"]
48+
#[deriving(Copy)]
5049
pub struct TyDesc {
5150
// sizeof(T)
5251
pub size: uint,
@@ -61,8 +60,6 @@ pub struct TyDesc {
6160
pub name: &'static str,
6261
}
6362

64-
impl Copy for TyDesc {}
65-
6663
extern "rust-intrinsic" {
6764

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

548-
impl Copy for TypeId {}
549-
550545
impl TypeId {
551546
/// Returns the `TypeId` of the type this generic function has been instantiated with
552547
pub fn of<T: 'static>() -> TypeId {

src/libcore/iter.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub use self::MinMaxResult::*;
5959
use clone::Clone;
6060
use cmp;
6161
use cmp::Ord;
62-
use kinds::Copy;
6362
use mem;
6463
use num::{ToPrimitive, Int};
6564
use ops::{Add, Deref, FnMut};
@@ -1168,16 +1167,14 @@ impl<A, I> CloneIteratorExt for I where I: Iterator<A> + Clone {
11681167
}
11691168

11701169
/// An iterator that repeats endlessly
1171-
#[deriving(Clone)]
1170+
#[deriving(Clone, Copy)]
11721171
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
11731172
#[stable]
11741173
pub struct Cycle<T> {
11751174
orig: T,
11761175
iter: T,
11771176
}
11781177

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

1643-
impl<T:Copy,A:Copy> Copy for Peekable<A,T> {}
1644-
16451641
impl<A, T: Iterator<A>> Iterator<A> for Peekable<A, T> {
16461642
#[inline]
16471643
fn next(&mut self) -> Option<A> {
@@ -2267,7 +2263,7 @@ impl<A, St, F> Iterator<A> for Unfold<A, St, F> where F: FnMut(&mut St) -> Optio
22672263

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

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

23032297
/// An iterator over the range [start, stop)
2304-
#[deriving(Clone)]
2298+
#[deriving(Clone, Copy)]
23052299
#[unstable = "may be refactored due to numerics reform or ops reform"]
23062300
pub struct Range<A> {
23072301
state: A,
23082302
stop: A,
23092303
one: A,
23102304
}
23112305

2312-
impl<A:Copy> Copy for Range<A> {}
2313-
23142306
/// Returns an iterator over the given range [start, stop) (that is, starting
23152307
/// at start (inclusive), and ending at stop (exclusive)).
23162308
///

0 commit comments

Comments
 (0)