From c32a48293aab01133ed9e131fe452fd8c88ff9de Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 22:26:17 -0500 Subject: [PATCH 01/23] libcollections: use `#[deriving(Copy)]` --- src/libcollections/binary_heap.rs | 4 +--- src/libcollections/enum_set.rs | 7 ++----- src/libcollections/slice.rs | 8 +++----- src/libcore/hash/sip.rs | 3 +-- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 9421159269896..be99c4c0bc724 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -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. diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index 49b66ce25f572..caa2051c3f9ca 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -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 @@ -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, @@ -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 diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index d3790e320ad65..3bf10192e5963 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -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; @@ -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)> { diff --git a/src/libcore/hash/sip.rs b/src/libcore/hash/sip.rs index 15f6768edce5b..e10f5a9fed188 100644 --- a/src/libcore/hash/sip.rs +++ b/src/libcore/hash/sip.rs @@ -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, @@ -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. From 30cefcbdfde6ff12c550914fede8180344d54857 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 22:35:22 -0500 Subject: [PATCH 02/23] libcore: use `#[deriving(Copy)]` --- src/libcore/atomic.rs | 4 +--- src/libcore/cmp.rs | 6 ++--- src/libcore/fmt/mod.rs | 6 ++--- src/libcore/fmt/num.rs | 8 ++----- src/libcore/fmt/rt.rs | 20 +++++----------- src/libcore/intrinsics.rs | 9 ++------ src/libcore/iter.rs | 16 ++++--------- src/libcore/kinds.rs | 8 ++----- src/libcore/num/mod.rs | 4 +--- src/libcore/ops.rs | 48 +++++++++++++-------------------------- src/libcore/option.rs | 7 +----- src/libcore/raw.rs | 6 ++--- src/libcore/result.rs | 6 +---- src/libcore/simd.rs | 43 ++++++++--------------------------- src/libcore/slice.rs | 4 +--- src/libcore/str.rs | 13 ++++------- 16 files changed, 57 insertions(+), 151 deletions(-) diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index bb2fed19e2afd..f6bc4dbde387a 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -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] @@ -53,6 +52,7 @@ pub struct AtomicPtr { /// 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] @@ -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 = diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index af82e6a00f39b..6e793be67e250 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -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. @@ -94,7 +94,7 @@ pub trait Eq for Sized?: PartialEq { } /// 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]. @@ -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. diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index cc940cd9e20a5..79fb11f385433 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -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 @@ -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, @@ -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. diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index 13cfcacf8dab9..cd8f226172a66 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -16,7 +16,6 @@ use fmt; use iter::DoubleEndedIteratorExt; -use kinds::Copy; use num::{Int, cast}; use slice::SliceExt; @@ -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); @@ -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); -impl Copy for RadixFmt where T: Copy, R: Copy {} - /// Constructs a radix formatter in the range of `2..36`. /// /// # Example diff --git a/src/libcore/fmt/rt.rs b/src/libcore/fmt/rt.rs index 748bd0bc4bd00..35dd0390f3087 100644 --- a/src/libcore/fmt/rt.rs +++ b/src/libcore/fmt/rt.rs @@ -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, @@ -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, @@ -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. @@ -89,5 +83,3 @@ pub enum Flag { /// being aware of the sign to be printed. FlagSignAwareZeroPad, } - -impl Copy for Flag {} diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index e2afee9905d7f..d8f103fa0f3dc 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -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, @@ -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 @@ -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() -> TypeId { diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index de5c0defb1ac2..1f83aad9c7cdc 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -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}; @@ -1168,7 +1167,7 @@ impl CloneIteratorExt for I where I: Iterator + 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 { @@ -1176,8 +1175,6 @@ pub struct Cycle { iter: T, } -impl Copy for Cycle {} - impl> Iterator for Cycle { #[inline] fn next(&mut self) -> Option { @@ -1635,13 +1632,12 @@ impl> 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 { iter: T, peeked: Option, } -impl Copy for Peekable {} - impl> Iterator for Peekable { #[inline] fn next(&mut self) -> Option { @@ -2267,7 +2263,7 @@ impl Iterator for Unfold 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 { /// The current state the counter is at (next value to be yielded) @@ -2276,8 +2272,6 @@ pub struct Counter { step: A, } -impl Copy for Counter {} - /// Creates a new counter with the specified start/step #[inline] #[unstable = "may be renamed"] @@ -2301,7 +2295,7 @@ impl + Clone> Iterator for Counter { } /// 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 { state: A, @@ -2309,8 +2303,6 @@ pub struct Range { one: A, } -impl Copy for Range {} - /// Returns an iterator over the given range [start, stop) (that is, starting /// at start (inclusive), and ending at stop (exclusive)). /// diff --git a/src/libcore/kinds.rs b/src/libcore/kinds.rs index 69f65e23389f3..93fd3f1b9f16f 100644 --- a/src/libcore/kinds.rs +++ b/src/libcore/kinds.rs @@ -225,11 +225,9 @@ pub mod marker { /// For more information about variance, refer to this Wikipedia /// article . #[lang="covariant_lifetime"] - #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] + #[deriving(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct CovariantLifetime<'a>; - impl<'a> Copy for CovariantLifetime<'a> {} - /// As `ContravariantType`, but for lifetime parameters. Using /// `ContravariantLifetime<'a>` indicates that it is ok to /// substitute a *shorter* lifetime for `'a` than the one you @@ -243,11 +241,9 @@ pub mod marker { /// For more information about variance, refer to this Wikipedia /// article . #[lang="contravariant_lifetime"] - #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] + #[deriving(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct ContravariantLifetime<'a>; - impl<'a> Copy for ContravariantLifetime<'a> {} - /// As `InvariantType`, but for lifetime parameters. Using /// `InvariantLifetime<'a>` indicates that it is not ok to /// substitute any other lifetime for `'a` besides its original diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index fcb2ca93054ce..b4f867b4bb417 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1225,7 +1225,7 @@ impl_num_cast! { f32, to_f32 } impl_num_cast! { f64, to_f64 } /// Used for representing the classification of floating point numbers -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] #[unstable = "may be renamed"] pub enum FPCategory { /// "Not a Number", often obtained by dividing by zero @@ -1240,8 +1240,6 @@ pub enum FPCategory { FPNormal, } -impl Copy for FPCategory {} - /// A built-in floating point number. // FIXME(#5527): In a future version of Rust, many of these functions will // become constants. diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 0090da3cdad6e..6e4beb2356e8f 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -88,10 +88,9 @@ pub trait Drop { /// calling `add`, and therefore, `main` prints `Adding!`. /// /// ```rust +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Add for Foo { /// fn add(&self, _rhs: &Foo) -> Foo { /// println!("Adding!"); @@ -170,10 +169,9 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `sub`, and therefore, `main` prints `Subtracting!`. /// /// ```rust +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Sub for Foo { /// fn sub(&self, _rhs: &Foo) -> Foo { /// println!("Subtracting!"); @@ -252,10 +250,9 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `mul`, and therefore, `main` prints `Multiplying!`. /// /// ```rust +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Mul for Foo { /// fn mul(&self, _rhs: &Foo) -> Foo { /// println!("Multiplying!"); @@ -334,10 +331,9 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `div`, and therefore, `main` prints `Dividing!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Div for Foo { /// fn div(&self, _rhs: &Foo) -> Foo { /// println!("Dividing!"); @@ -416,10 +412,9 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `rem`, and therefore, `main` prints `Remainder-ing!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Rem for Foo { /// fn rem(&self, _rhs: &Foo) -> Foo { /// println!("Remainder-ing!"); @@ -527,10 +522,9 @@ rem_float_impl! { f64, fmod } /// `neg`, and therefore, `main` prints `Negating!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Neg for Foo { /// fn neg(&self) -> Foo { /// println!("Negating!"); @@ -639,10 +633,9 @@ neg_uint_impl! { u64, i64 } /// `not`, and therefore, `main` prints `Not-ing!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Not for Foo { /// fn not(&self) -> Foo { /// println!("Not-ing!"); @@ -724,10 +717,9 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl BitAnd for Foo { /// fn bitand(&self, _rhs: &Foo) -> Foo { /// println!("Bitwise And-ing!"); @@ -806,10 +798,9 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl BitOr for Foo { /// fn bitor(&self, _rhs: &Foo) -> Foo { /// println!("Bitwise Or-ing!"); @@ -888,10 +879,9 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl BitXor for Foo { /// fn bitxor(&self, _rhs: &Foo) -> Foo { /// println!("Bitwise Xor-ing!"); @@ -970,10 +960,9 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `shl`, and therefore, `main` prints `Shifting left!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Shl for Foo { /// fn shl(&self, _rhs: &Foo) -> Foo { /// println!("Shifting left!"); @@ -1056,10 +1045,9 @@ shl_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `shr`, and therefore, `main` prints `Shifting right!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Shr for Foo { /// fn shr(&self, _rhs: &Foo) -> Foo { /// println!("Shifting right!"); @@ -1139,10 +1127,9 @@ shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `index`, and therefore, `main` prints `Indexing!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Index for Foo { /// fn index<'a>(&'a self, _index: &Foo) -> &'a Foo { /// println!("Indexing!"); @@ -1169,10 +1156,9 @@ pub trait Index for Sized? { /// calling `index_mut`, and therefore, `main` prints `Indexing!`. /// /// ``` +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl IndexMut for Foo { /// fn index_mut<'a>(&'a mut self, _index: &Foo) -> &'a mut Foo { /// println!("Indexing!"); @@ -1199,10 +1185,9 @@ pub trait IndexMut for Sized? { /// calling `slice_to`, and therefore, `main` prints `Slicing!`. /// /// ```ignore +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl Slice for Foo { /// fn as_slice_<'a>(&'a self) -> &'a Foo { /// println!("Slicing!"); @@ -1247,10 +1232,9 @@ pub trait Slice for Sized? { /// calling `slice_from_mut`, and therefore, `main` prints `Slicing!`. /// /// ```ignore +/// #[deriving(Copy)] /// struct Foo; /// -/// impl Copy for Foo {} -/// /// impl SliceMut for Foo { /// fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo { /// println!("Slicing!"); diff --git a/src/libcore/option.rs b/src/libcore/option.rs index deb1cea1c0ec3..314b47fc6476b 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -149,7 +149,6 @@ use cmp::{Eq, Ord}; use default::Default; use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator}; use iter::{ExactSizeIterator}; -use kinds::Copy; use mem; use result::Result; use result::Result::{Ok, Err}; @@ -164,7 +163,7 @@ use ops::{Deref, FnOnce}; // which basically means it must be `Option`. /// The `Option` type. -#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show, Hash)] +#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Show, Hash)] #[stable] pub enum Option { /// No value @@ -920,7 +919,3 @@ impl> FromIterator> for Option { } } } - -#[stable] -impl Copy for Option {} - diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index be2f4e590a359..d70c96d8c1662 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -33,25 +33,23 @@ impl Copy for Slice {} /// The representation of a Rust closure #[repr(C)] +#[deriving(Copy)] pub struct Closure { pub code: *mut (), pub env: *mut (), } -impl Copy for Closure {} - /// The representation of a Rust trait object. /// /// This struct does not have a `Repr` implementation /// because there is no way to refer to all trait objects generically. #[repr(C)] +#[deriving(Copy)] pub struct TraitObject { pub data: *mut (), pub vtable: *mut (), } -impl Copy for TraitObject {} - /// This trait is meant to map equivalences between raw structs and their /// corresponding rust values. pub trait Repr for Sized? { diff --git a/src/libcore/result.rs b/src/libcore/result.rs index e12666a2adff3..00a2a3d5854d8 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -232,7 +232,6 @@ use self::Result::*; -use kinds::Copy; use std::fmt::Show; use slice; use slice::AsSlice; @@ -244,7 +243,7 @@ use ops::{FnMut, FnOnce}; /// `Result` is a type that represents either success (`Ok`) or failure (`Err`). /// /// See the [`std::result`](index.html) module documentation for details. -#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show, Hash)] +#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Show, Hash)] #[must_use] #[stable] pub enum Result { @@ -919,6 +918,3 @@ pub fn fold Copy for Result {} - diff --git a/src/libcore/simd.rs b/src/libcore/simd.rs index 252a24e3aa913..0b0e6ff95c659 100644 --- a/src/libcore/simd.rs +++ b/src/libcore/simd.rs @@ -37,93 +37,70 @@ #![allow(non_camel_case_types)] #![allow(missing_docs)] -use kinds::Copy; - #[experimental] #[simd] -#[deriving(Show)] +#[deriving(Copy, Show)] #[repr(C)] pub struct i8x16(pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8, pub i8); -impl Copy for i8x16 {} - #[experimental] #[simd] -#[deriving(Show)] +#[deriving(Copy, Show)] #[repr(C)] pub struct i16x8(pub i16, pub i16, pub i16, pub i16, pub i16, pub i16, pub i16, pub i16); -impl Copy for i16x8 {} - #[experimental] #[simd] -#[deriving(Show)] +#[deriving(Copy, Show)] #[repr(C)] pub struct i32x4(pub i32, pub i32, pub i32, pub i32); -impl Copy for i32x4 {} - #[experimental] #[simd] -#[deriving(Show)] +#[deriving(Copy, Show)] #[repr(C)] pub struct i64x2(pub i64, pub i64); -impl Copy for i64x2 {} - #[experimental] #[simd] -#[deriving(Show)] +#[deriving(Copy, Show)] #[repr(C)] pub struct u8x16(pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8, pub u8); -impl Copy for u8x16 {} - #[experimental] #[simd] -#[deriving(Show)] +#[deriving(Copy, Show)] #[repr(C)] pub struct u16x8(pub u16, pub u16, pub u16, pub u16, pub u16, pub u16, pub u16, pub u16); -impl Copy for u16x8 {} - #[experimental] #[simd] -#[deriving(Show)] +#[deriving(Copy, Show)] #[repr(C)] pub struct u32x4(pub u32, pub u32, pub u32, pub u32); -impl Copy for u32x4 {} - #[experimental] #[simd] -#[deriving(Show)] +#[deriving(Copy, Show)] #[repr(C)] pub struct u64x2(pub u64, pub u64); -impl Copy for u64x2 {} - #[experimental] #[simd] -#[deriving(Show)] +#[deriving(Copy, Show)] #[repr(C)] pub struct f32x4(pub f32, pub f32, pub f32, pub f32); -impl Copy for f32x4 {} - #[experimental] #[simd] -#[deriving(Show)] +#[deriving(Copy, Show)] #[repr(C)] pub struct f64x2(pub f64, pub f64); - -impl Copy for f64x2 {} - diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 2ee609552454a..f5d117bca9fc8 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -1229,7 +1229,7 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> { /// index of the matching element. `NotFound` means the search /// succeeded, and the contained value is an index where a matching /// value could be inserted while maintaining sort order. -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] #[experimental = "needs review"] pub enum BinarySearchResult { /// The index of the found value. @@ -1238,8 +1238,6 @@ pub enum BinarySearchResult { NotFound(uint) } -impl Copy for BinarySearchResult {} - #[experimental = "needs review"] impl BinarySearchResult { /// Converts a `Found` to `Some`, `NotFound` to `None`. diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 8fe41c0bd89c2..a89a7970ae9c4 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -27,7 +27,7 @@ use default::Default; use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator}; use iter::{DoubleEndedIteratorExt, ExactSizeIterator}; use iter::range; -use kinds::{Copy, Sized}; +use kinds::Sized; use mem; use num::Int; use option::Option; @@ -165,13 +165,11 @@ Section: Iterators /// Iterator for the char (representing *Unicode Scalar Values*) of a string /// /// Created with the method `.chars()`. -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct Chars<'a> { iter: slice::Items<'a, u8> } -impl<'a> Copy for Chars<'a> {} - // Return the initial codepoint accumulator for the first byte. // The first byte is special, only want bottom 5 bits for width 2, 4 bits // for width 3, and 3 bits for width 4 @@ -998,7 +996,7 @@ pub struct Utf16Items<'a> { iter: slice::Items<'a, u16> } /// The possibilities for values decoded from a `u16` stream. -#[deriving(PartialEq, Eq, Clone, Show)] +#[deriving(Copy, PartialEq, Eq, Clone, Show)] pub enum Utf16Item { /// A valid codepoint. ScalarValue(char), @@ -1006,8 +1004,6 @@ pub enum Utf16Item { LoneSurrogate(u16) } -impl Copy for Utf16Item {} - impl Utf16Item { /// Convert `self` to a `char`, taking `LoneSurrogate`s to the /// replacement character (U+FFFD). @@ -1144,6 +1140,7 @@ pub fn utf8_char_width(b: u8) -> uint { /// Struct that contains a `char` and the index of the first byte of /// the next `char` in a string. This can be used as a data structure /// for iterating over the UTF-8 bytes of a string. +#[deriving(Copy)] pub struct CharRange { /// Current `char` pub ch: char, @@ -1151,8 +1148,6 @@ pub struct CharRange { pub next: uint, } -impl Copy for CharRange {} - /// Mask of the value bits of a continuation byte const CONT_MASK: u8 = 0b0011_1111u8; /// Value of the tag bits (tag mask is !CONT_MASK) of a continuation byte From 4c62c76ef99aab3a752c4ebd74b63819cabee98f Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 22:36:39 -0500 Subject: [PATCH 03/23] libfmt_macros: use `#[deriving(Copy)]` --- src/libfmt_macros/lib.rs | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 444806e78c129..3099bf559e4bf 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -35,7 +35,7 @@ use std::string; /// A piece is a portion of the format string which represents the next part /// to emit. These are emitted as a stream by the `Parser` class. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum Piece<'a> { /// A literal string which should directly be emitted String(&'a str), @@ -44,10 +44,8 @@ pub enum Piece<'a> { NextArgument(Argument<'a>), } -impl<'a> Copy for Piece<'a> {} - /// Representation of an argument specification. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub struct Argument<'a> { /// Where to find this argument pub position: Position<'a>, @@ -55,10 +53,8 @@ pub struct Argument<'a> { pub format: FormatSpec<'a>, } -impl<'a> Copy for Argument<'a> {} - /// Specification for the formatting of an argument in the format string. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub struct FormatSpec<'a> { /// Optionally specified character to fill alignment with pub fill: Option, @@ -76,10 +72,8 @@ pub struct FormatSpec<'a> { pub ty: &'a str } -impl<'a> Copy for FormatSpec<'a> {} - /// Enum describing where an argument for a format can be located. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum Position<'a> { /// The argument will be in the next position. This is the default. ArgumentNext, @@ -89,10 +83,8 @@ pub enum Position<'a> { ArgumentNamed(&'a str), } -impl<'a> Copy for Position<'a> {} - /// Enum of alignments which are supported. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum Alignment { /// The value will be aligned to the left. AlignLeft, @@ -104,11 +96,9 @@ pub enum Alignment { AlignUnknown, } -impl Copy for Alignment {} - /// Various flags which can be applied to format strings. The meaning of these /// flags is defined by the formatters themselves. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum Flag { /// A `+` will be used to denote positive numbers. FlagSignPlus, @@ -122,11 +112,9 @@ pub enum Flag { FlagSignAwareZeroPad, } -impl Copy for Flag {} - /// A count is used for the precision and width parameters of an integer, and /// can reference either an argument or a literal integer. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum Count<'a> { /// The count is specified explicitly. CountIs(uint), @@ -140,8 +128,6 @@ pub enum Count<'a> { CountImplied, } -impl<'a> Copy for Count<'a> {} - /// The parser structure for interpreting the input format string. This is /// modelled as an iterator over `Piece` structures to form a stream of tokens /// being output. From c407785ac0b535dc98e9bf2d9c595111cfff31cc Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 22:37:29 -0500 Subject: [PATCH 04/23] libgetopts: use `#[deriving(Copy)]` --- src/libgetopts/lib.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 38729eece5ab5..b45d0c9b01ecd 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -118,7 +118,7 @@ pub enum Name { } /// Describes whether an option has an argument. -#[deriving(Clone, PartialEq, Eq)] +#[deriving(Clone, Copy, PartialEq, Eq)] pub enum HasArg { /// The option requires an argument. Yes, @@ -128,10 +128,8 @@ pub enum HasArg { Maybe, } -impl Copy for HasArg {} - /// Describes how often an option may occur. -#[deriving(Clone, PartialEq, Eq)] +#[deriving(Clone, Copy, PartialEq, Eq)] pub enum Occur { /// The option occurs once. Req, @@ -141,8 +139,6 @@ pub enum Occur { Multi, } -impl Copy for Occur {} - /// A description of a possible option. #[deriving(Clone, PartialEq, Eq)] pub struct Opt { @@ -211,7 +207,7 @@ pub enum Fail { } /// The type of failure that occurred. -#[deriving(PartialEq, Eq)] +#[deriving(Copy, PartialEq, Eq)] #[allow(missing_docs)] pub enum FailType { ArgumentMissing_, @@ -221,8 +217,6 @@ pub enum FailType { UnexpectedArgument_, } -impl Copy for FailType {} - /// The result of parsing a command line with a set of options. pub type Result = result::Result; @@ -839,22 +833,22 @@ pub fn short_usage(program_name: &str, opts: &[OptGroup]) -> String { line } +#[deriving(Copy)] enum SplitWithinState { A, // leading whitespace, initial state B, // words C, // internal and trailing whitespace } -impl Copy for SplitWithinState {} +#[deriving(Copy)] enum Whitespace { Ws, // current char is whitespace Cr // current char is not whitespace } -impl Copy for Whitespace {} +#[deriving(Copy)] enum LengthLimit { UnderLim, // current char makes current substring still fit in limit OverLim // current char makes current substring no longer fit in limit } -impl Copy for LengthLimit {} /// Splits a string into substrings with possibly internal whitespace, From e0a88a78da2632f615f387a2bdd45777f74f073f Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 22:43:43 -0500 Subject: [PATCH 05/23] liblog: use `#[deriving(Copy)]` --- src/liblog/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 257ce79b58890..2bf9af9027182 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -232,11 +232,9 @@ struct DefaultLogger { } /// Wraps the log level with fmt implementations. -#[deriving(PartialEq, PartialOrd)] +#[deriving(Copy, PartialEq, PartialOrd)] pub struct LogLevel(pub u32); -impl Copy for LogLevel {} - impl fmt::Show for LogLevel { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let LogLevel(level) = *self; @@ -341,14 +339,13 @@ pub struct LogRecord<'a> { } #[doc(hidden)] +#[deriving(Copy)] pub struct LogLocation { pub module_path: &'static str, pub file: &'static str, pub line: uint, } -impl Copy for LogLocation {} - /// Tests whether a given module's name is enabled for a particular level of /// logging. This is the second layer of defense about determining whether a /// module's log statement should be emitted or not. From a18d090c3cf6223b90c5a39e66ddef3e1932c7c7 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 22:45:18 -0500 Subject: [PATCH 06/23] librand: use `#[deriving(Copy)]` --- src/librand/chacha.rs | 3 +-- src/librand/distributions/exponential.rs | 7 ++----- src/librand/distributions/normal.rs | 10 +++------- src/librand/isaac.rs | 6 ++---- src/librand/lib.rs | 1 + src/librand/reseeding.rs | 3 +-- 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/librand/chacha.rs b/src/librand/chacha.rs index 5cbc5a0a61cc4..6fc92e1e94fcb 100644 --- a/src/librand/chacha.rs +++ b/src/librand/chacha.rs @@ -29,14 +29,13 @@ const CHACHA_ROUNDS: uint = 20; // Cryptographically secure from 8 upwards as of /// [1]: D. J. Bernstein, [*ChaCha, a variant of /// Salsa20*](http://cr.yp.to/chacha.html) +#[deriving(Copy)] pub struct ChaChaRng { buffer: [u32, ..STATE_WORDS], // Internal buffer of output state: [u32, ..STATE_WORDS], // Initial state index: uint, // Index into state } -impl Copy for ChaChaRng {} - static EMPTY: ChaChaRng = ChaChaRng { buffer: [0, ..STATE_WORDS], state: [0, ..STATE_WORDS], diff --git a/src/librand/distributions/exponential.rs b/src/librand/distributions/exponential.rs index 9a9f31e9339c8..431a530726a08 100644 --- a/src/librand/distributions/exponential.rs +++ b/src/librand/distributions/exponential.rs @@ -10,7 +10,6 @@ //! The exponential distribution. -use core::kinds::Copy; use core::num::Float; use {Rng, Rand}; @@ -30,10 +29,9 @@ use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample}; /// Generate Normal Random /// Samples*](http://www.doornik.com/research/ziggurat.pdf). Nuffield /// College, Oxford +#[deriving(Copy)] pub struct Exp1(pub f64); -impl Copy for Exp1 {} - // This could be done via `-rng.gen::().ln()` but that is slower. impl Rand for Exp1 { #[inline] @@ -69,13 +67,12 @@ impl Rand for Exp1 { /// let v = exp.ind_sample(&mut rand::task_rng()); /// println!("{} is from a Exp(2) distribution", v); /// ``` +#[deriving(Copy)] pub struct Exp { /// `lambda` stored as `1/lambda`, since this is what we scale by. lambda_inverse: f64 } -impl Copy for Exp {} - impl Exp { /// Construct a new `Exp` with the given shape parameter /// `lambda`. Panics if `lambda <= 0`. diff --git a/src/librand/distributions/normal.rs b/src/librand/distributions/normal.rs index f5261f1db82ee..16413af626739 100644 --- a/src/librand/distributions/normal.rs +++ b/src/librand/distributions/normal.rs @@ -10,7 +10,6 @@ //! The normal and derived distributions. -use core::kinds::Copy; use core::num::Float; use {Rng, Rand, Open01}; @@ -29,10 +28,9 @@ use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample}; /// Generate Normal Random /// Samples*](http://www.doornik.com/research/ziggurat.pdf). Nuffield /// College, Oxford +#[deriving(Copy)] pub struct StandardNormal(pub f64); -impl Copy for StandardNormal {} - impl Rand for StandardNormal { fn rand(rng: &mut R) -> StandardNormal { #[inline] @@ -86,13 +84,12 @@ impl Rand for StandardNormal { /// let v = normal.ind_sample(&mut rand::task_rng()); /// println!("{} is from a N(2, 9) distribution", v) /// ``` +#[deriving(Copy)] pub struct Normal { mean: f64, std_dev: f64, } -impl Copy for Normal {} - impl Normal { /// Construct a new `Normal` distribution with the given mean and /// standard deviation. @@ -135,12 +132,11 @@ impl IndependentSample for Normal { /// let v = log_normal.ind_sample(&mut rand::task_rng()); /// println!("{} is from an ln N(2, 9) distribution", v) /// ``` +#[deriving(Copy)] pub struct LogNormal { norm: Normal } -impl Copy for LogNormal {} - impl LogNormal { /// Construct a new `LogNormal` distribution with the given mean /// and standard deviation. diff --git a/src/librand/isaac.rs b/src/librand/isaac.rs index 2499d7f529fd5..3cb1f51a6a801 100644 --- a/src/librand/isaac.rs +++ b/src/librand/isaac.rs @@ -29,6 +29,7 @@ const RAND_SIZE_UINT: uint = 1 << (RAND_SIZE_LEN as uint); /// /// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number /// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html) +#[deriving(Copy)] pub struct IsaacRng { cnt: u32, rsl: [u32, ..RAND_SIZE_UINT], @@ -38,8 +39,6 @@ pub struct IsaacRng { c: u32 } -impl Copy for IsaacRng {} - static EMPTY: IsaacRng = IsaacRng { cnt: 0, rsl: [0, ..RAND_SIZE_UINT], @@ -265,6 +264,7 @@ const RAND_SIZE_64: uint = 1 << RAND_SIZE_64_LEN; /// /// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number /// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html) +#[deriving(Copy)] pub struct Isaac64Rng { cnt: uint, rsl: [u64, .. RAND_SIZE_64], @@ -274,8 +274,6 @@ pub struct Isaac64Rng { c: u64, } -impl Copy for Isaac64Rng {} - static EMPTY_64: Isaac64Rng = Isaac64Rng { cnt: 0, rsl: [0, .. RAND_SIZE_64], diff --git a/src/librand/lib.rs b/src/librand/lib.rs index dfcdad481a91a..514ff81da518e 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -501,6 +501,7 @@ pub struct Closed01(pub F); #[cfg(not(test))] mod std { pub use core::{option, fmt}; // panic!() + pub use core::kinds; } #[cfg(test)] diff --git a/src/librand/reseeding.rs b/src/librand/reseeding.rs index 46ee67940f269..94a11c040e497 100644 --- a/src/librand/reseeding.rs +++ b/src/librand/reseeding.rs @@ -133,10 +133,9 @@ pub trait Reseeder { /// Reseed an RNG using a `Default` instance. This reseeds by /// replacing the RNG with the result of a `Default::default` call. +#[deriving(Copy)] pub struct ReseedWithDefault; -impl Copy for ReseedWithDefault {} - impl Reseeder for ReseedWithDefault { fn reseed(&mut self, rng: &mut R) { *rng = Default::default(); From fd4a5d9ef12a87cad61f2fa5dd0a011df263a2d0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 22:46:05 -0500 Subject: [PATCH 07/23] librbml: use `#[deriving(Copy)]` --- src/librbml/lib.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index bb7af92eb5452..19e79b1eb7b2d 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -41,15 +41,13 @@ use std::str; pub mod io; /// Common data structures -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct Doc<'a> { pub data: &'a [u8], pub start: uint, pub end: uint, } -impl<'doc> Copy for Doc<'doc> {} - impl<'doc> Doc<'doc> { pub fn new(data: &'doc [u8]) -> Doc<'doc> { Doc { data: data, start: 0u, end: data.len() } @@ -73,7 +71,7 @@ pub struct TaggedDoc<'a> { pub doc: Doc<'a>, } -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum EbmlEncoderTag { EsUint, // 0 EsU64, // 1 @@ -107,8 +105,6 @@ pub enum EbmlEncoderTag { EsLabel, // Used only when debugging } -impl Copy for EbmlEncoderTag {} - #[deriving(Show)] pub enum Error { IntTooBig(uint), @@ -151,13 +147,12 @@ pub mod reader { ) } + #[deriving(Copy)] pub struct Res { pub val: uint, pub next: uint } - impl Copy for Res {} - #[inline(never)] fn vuint_at_slow(data: &[u8], start: uint) -> DecodeResult { let a = data[start]; From f2ef2cda526ba601cf5091f65cb12962a0ae0956 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 22:46:59 -0500 Subject: [PATCH 08/23] libregex: use `#[deriving(Copy)]` --- src/libregex/parse.rs | 4 +--- src/libregex/re.rs | 3 +-- src/libregex/vm.rs | 6 ++---- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index 60cf45aeddc17..78558a322665d 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -77,14 +77,12 @@ pub enum Repeater { OneMore, } -#[deriving(Show, Clone)] +#[deriving(Copy, Show, Clone)] pub enum Greed { Greedy, Ungreedy, } -impl Copy for Greed {} - impl Greed { pub fn is_greedy(&self) -> bool { match *self { diff --git a/src/libregex/re.rs b/src/libregex/re.rs index 53181bfbb7e3f..151587e423abb 100644 --- a/src/libregex/re.rs +++ b/src/libregex/re.rs @@ -126,6 +126,7 @@ pub struct ExDynamic { } #[doc(hidden)] +#[deriving(Copy)] pub struct ExNative { #[doc(hidden)] pub original: &'static str, @@ -135,8 +136,6 @@ pub struct ExNative { pub prog: fn(MatchKind, &str, uint, uint) -> Vec> } -impl Copy for ExNative {} - impl Clone for ExNative { fn clone(&self) -> ExNative { *self diff --git a/src/libregex/vm.rs b/src/libregex/vm.rs index 15a678d2e7459..990d5a159f60d 100644 --- a/src/libregex/vm.rs +++ b/src/libregex/vm.rs @@ -50,6 +50,7 @@ use unicode::regex::PERLW; pub type CaptureLocs = Vec>; /// Indicates the type of match to be performed by the VM. +#[deriving(Copy)] pub enum MatchKind { /// Only checks if a match exists or not. Does not return location. Exists, @@ -60,8 +61,6 @@ pub enum MatchKind { Submatches, } -impl Copy for MatchKind {} - /// Runs an NFA simulation on the compiled expression given on the search text /// `input`. The search begins at byte index `start` and ends at byte index /// `end`. (The range is specified here so that zero-width assertions will work @@ -96,6 +95,7 @@ struct Nfa<'r, 't> { /// Indicates the next action to take after a single non-empty instruction /// is processed. +#[deriving(Copy)] pub enum StepState { /// This is returned if and only if a Match instruction is reached and /// we only care about the existence of a match. It instructs the VM to @@ -109,8 +109,6 @@ pub enum StepState { StepContinue, } -impl Copy for StepState {} - impl<'r, 't> Nfa<'r, 't> { fn run(&mut self) -> CaptureLocs { let ncaps = match self.which { From e64a0072d66f0071f47325711a226f34d7b76f05 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:03:34 -0500 Subject: [PATCH 09/23] librustc: use `#[deriving(Copy)]` --- src/librustc/lint/builtin.rs | 63 +++---- src/librustc/lint/mod.rs | 15 +- src/librustc/metadata/common.rs | 3 +- src/librustc/metadata/csearch.rs | 3 +- src/librustc/metadata/cstore.rs | 8 +- src/librustc/metadata/decoder.rs | 4 +- src/librustc/metadata/filesearch.rs | 3 +- src/librustc/metadata/tydecode.rs | 3 +- src/librustc/middle/cfg/construct.rs | 3 +- src/librustc/middle/cfg/mod.rs | 3 +- src/librustc/middle/check_loop.rs | 7 +- src/librustc/middle/check_match.rs | 3 +- src/librustc/middle/check_static.rs | 4 +- src/librustc/middle/const_eval.rs | 3 +- src/librustc/middle/dataflow.rs | 4 +- src/librustc/middle/def.rs | 12 +- src/librustc/middle/effect.rs | 4 +- src/librustc/middle/expr_use_visitor.rs | 23 +-- src/librustc/middle/fast_reject.rs | 4 +- src/librustc/middle/graph.rs | 12 +- src/librustc/middle/infer/mod.rs | 12 +- .../middle/infer/region_inference/mod.rs | 23 +-- src/librustc/middle/infer/type_variable.rs | 4 +- src/librustc/middle/infer/unify.rs | 3 +- src/librustc/middle/lang_items.rs | 4 +- src/librustc/middle/liveness.rs | 27 +-- src/librustc/middle/mem_categorization.rs | 37 +--- src/librustc/middle/region.rs | 7 +- src/librustc/middle/resolve.rs | 70 ++----- src/librustc/middle/resolve_lifetime.rs | 4 +- src/librustc/middle/subst.rs | 4 +- src/librustc/middle/traits/select.rs | 4 +- src/librustc/middle/ty.rs | 174 +++++------------- src/librustc/session/config.rs | 20 +- src/librustc/util/common.rs | 4 +- src/librustc/util/nodemap.rs | 4 +- 36 files changed, 159 insertions(+), 426 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index f6fd9f60e5c3f..88b12aa5660c9 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -56,10 +56,9 @@ declare_lint! { "suggest using `loop { }` instead of `while true { }`" } +#[deriving(Copy)] pub struct WhileTrue; -impl Copy for WhileTrue {} - impl LintPass for WhileTrue { fn get_lints(&self) -> LintArray { lint_array!(WHILE_TRUE) @@ -83,10 +82,9 @@ declare_lint! { "detects unnecessary type casts that can be removed" } +#[deriving(Copy)] pub struct UnusedCasts; -impl Copy for UnusedCasts {} - impl LintPass for UnusedCasts { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_TYPECASTS) @@ -126,13 +124,12 @@ declare_lint! { "shift exceeds the type's number of bits" } +#[deriving(Copy)] pub struct TypeLimits { /// Id of the last visited negated expression negated_expr_id: ast::NodeId, } -impl Copy for TypeLimits {} - impl TypeLimits { pub fn new() -> TypeLimits { TypeLimits { @@ -442,10 +439,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ImproperCTypesVisitor<'a, 'tcx> { } } +#[deriving(Copy)] pub struct ImproperCTypes; -impl Copy for ImproperCTypes {} - impl LintPass for ImproperCTypes { fn get_lints(&self) -> LintArray { lint_array!(IMPROPER_CTYPES) @@ -486,10 +482,9 @@ declare_lint! { "use of owned (Box type) heap memory" } +#[deriving(Copy)] pub struct BoxPointers; -impl Copy for BoxPointers {} - impl BoxPointers { fn check_heap_type<'a, 'tcx>(&self, cx: &Context<'a, 'tcx>, span: Span, ty: Ty<'tcx>) { @@ -627,10 +622,9 @@ declare_lint! { "detects attributes that were not used by the compiler" } +#[deriving(Copy)] pub struct UnusedAttributes; -impl Copy for UnusedAttributes {} - impl LintPass for UnusedAttributes { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_ATTRIBUTES) @@ -711,10 +705,9 @@ declare_lint! { "path statements with no effect" } +#[deriving(Copy)] pub struct PathStatements; -impl Copy for PathStatements {} - impl LintPass for PathStatements { fn get_lints(&self) -> LintArray { lint_array!(PATH_STATEMENTS) @@ -746,10 +739,9 @@ declare_lint! { "unused result of an expression in a statement" } +#[deriving(Copy)] pub struct UnusedResults; -impl Copy for UnusedResults {} - impl LintPass for UnusedResults { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_MUST_USE, UNUSED_RESULTS) @@ -815,10 +807,9 @@ declare_lint! { "types, variants, traits and type parameters should have camel case names" } +#[deriving(Copy)] pub struct NonCamelCaseTypes; -impl Copy for NonCamelCaseTypes {} - impl NonCamelCaseTypes { fn check_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) { fn is_camel_case(ident: ast::Ident) -> bool { @@ -939,10 +930,9 @@ declare_lint! { "methods, functions, lifetime parameters and modules should have snake case names" } +#[deriving(Copy)] pub struct NonSnakeCase; -impl Copy for NonSnakeCase {} - impl NonSnakeCase { fn check_snake_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) { fn is_snake_case(ident: ast::Ident) -> bool { @@ -1053,10 +1043,9 @@ declare_lint! { "static constants should have uppercase identifiers" } +#[deriving(Copy)] pub struct NonUpperCaseGlobals; -impl Copy for NonUpperCaseGlobals {} - impl LintPass for NonUpperCaseGlobals { fn get_lints(&self) -> LintArray { lint_array!(NON_UPPER_CASE_GLOBALS) @@ -1107,10 +1096,9 @@ declare_lint! { "`if`, `match`, `while` and `return` do not need parentheses" } +#[deriving(Copy)] pub struct UnusedParens; -impl Copy for UnusedParens {} - impl UnusedParens { fn check_unused_parens_core(&self, cx: &Context, value: &ast::Expr, msg: &str, struct_lit_needs_parens: bool) { @@ -1202,10 +1190,9 @@ declare_lint! { "unnecessary braces around an imported item" } +#[deriving(Copy)] pub struct UnusedImportBraces; -impl Copy for UnusedImportBraces {} - impl LintPass for UnusedImportBraces { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_IMPORT_BRACES) @@ -1242,10 +1229,9 @@ declare_lint! { "using `Struct { x: x }` instead of `Struct { x }`" } +#[deriving(Copy)] pub struct NonShorthandFieldPatterns; -impl Copy for NonShorthandFieldPatterns {} - impl LintPass for NonShorthandFieldPatterns { fn get_lints(&self) -> LintArray { lint_array!(NON_SHORTHAND_FIELD_PATTERNS) @@ -1276,10 +1262,9 @@ declare_lint! { "unnecessary use of an `unsafe` block" } +#[deriving(Copy)] pub struct UnusedUnsafe; -impl Copy for UnusedUnsafe {} - impl LintPass for UnusedUnsafe { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_UNSAFE) @@ -1302,10 +1287,9 @@ declare_lint! { "usage of an `unsafe` block" } +#[deriving(Copy)] pub struct UnsafeBlocks; -impl Copy for UnsafeBlocks {} - impl LintPass for UnsafeBlocks { fn get_lints(&self) -> LintArray { lint_array!(UNSAFE_BLOCKS) @@ -1327,10 +1311,9 @@ declare_lint! { "detect mut variables which don't need to be mutable" } +#[deriving(Copy)] pub struct UnusedMut; -impl Copy for UnusedMut {} - impl UnusedMut { fn check_unused_mut_pat(&self, cx: &Context, pats: &[P]) { // collect all mutable pattern and group their NodeIDs by their Identifier to @@ -1397,10 +1380,9 @@ declare_lint! { "detects unnecessary allocations that can be eliminated" } +#[deriving(Copy)] pub struct UnusedAllocation; -impl Copy for UnusedAllocation {} - impl LintPass for UnusedAllocation { fn get_lints(&self) -> LintArray { lint_array!(UNUSED_ALLOCATION) @@ -1589,10 +1571,9 @@ impl LintPass for MissingDoc { } } +#[deriving(Copy)] pub struct MissingCopyImplementations; -impl Copy for MissingCopyImplementations {} - impl LintPass for MissingCopyImplementations { fn get_lints(&self) -> LintArray { lint_array!(MISSING_COPY_IMPLEMENTATIONS) @@ -1665,10 +1646,9 @@ declare_lint! { /// Checks for use of items with `#[deprecated]`, `#[experimental]` and /// `#[unstable]` attributes, or no stability attribute. +#[deriving(Copy)] pub struct Stability; -impl Copy for Stability {} - impl Stability { fn lint(&self, cx: &Context, id: ast::DefId, span: Span) { let stability = stability::lookup(cx.tcx, id); @@ -1903,10 +1883,9 @@ declare_lint!{ /// Does nothing as a lint pass, but registers some `Lint`s /// which are used by other parts of the compiler. +#[deriving(Copy)] pub struct HardwiredLints; -impl Copy for HardwiredLints {} - impl LintPass for HardwiredLints { fn get_lints(&self) -> LintArray { lint_array!( diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 79d57305f9642..009a1d444dc13 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -42,6 +42,7 @@ use syntax::ast; pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate, gather_attrs}; /// Specification of a single lint. +#[deriving(Copy)] pub struct Lint { /// A string identifier for the lint. /// @@ -64,8 +65,6 @@ pub struct Lint { pub desc: &'static str, } -impl Copy for Lint {} - impl Lint { /// Get the lint's name, with ASCII letters converted to lowercase. pub fn name_lower(&self) -> String { @@ -175,14 +174,12 @@ pub trait LintPass { pub type LintPassObject = Box; /// Identifies a lint known to the compiler. -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct LintId { // Identity is based on pointer equality of this field. lint: &'static Lint, } -impl Copy for LintId {} - impl PartialEq for LintId { fn eq(&self, other: &LintId) -> bool { (self.lint as *const Lint) == (other.lint as *const Lint) @@ -213,13 +210,11 @@ impl LintId { } /// Setting for how to handle a lint. -#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord)] +#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord)] pub enum Level { Allow, Warn, Deny, Forbid } -impl Copy for Level {} - impl Level { /// Convert a level to a lower-case string. pub fn as_str(self) -> &'static str { @@ -244,7 +239,7 @@ impl Level { } /// How a lint level was set. -#[deriving(Clone, PartialEq, Eq)] +#[deriving(Clone, Copy, PartialEq, Eq)] pub enum LintSource { /// Lint is at the default level as declared /// in rustc or a plugin. @@ -257,8 +252,6 @@ pub enum LintSource { CommandLine, } -impl Copy for LintSource {} - pub type LevelSource = (Level, LintSource); pub mod builtin; diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index b698e4fcc7f7b..03e436e98df46 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -113,7 +113,7 @@ pub const tag_items_data_item_reexport_def_id: uint = 0x39; pub const tag_items_data_item_reexport_name: uint = 0x3a; // used to encode crate_ctxt side tables -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] #[repr(uint)] pub enum astencode_tag { // Reserves 0x40 -- 0x5f tag_ast = 0x40, @@ -145,7 +145,6 @@ pub enum astencode_tag { // Reserves 0x40 -- 0x5f tag_table_object_cast_map = 0x57, } -impl Copy for astencode_tag {} static first_astencode_tag: uint = tag_ast as uint; static last_astencode_tag: uint = tag_table_object_cast_map as uint; impl astencode_tag { diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 4cbb1babf9a2c..a474af7c6e1ff 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -33,14 +33,13 @@ use syntax::parse::token; use std::collections::hash_map::HashMap; +#[deriving(Copy)] pub struct MethodInfo { pub name: ast::Name, pub def_id: ast::DefId, pub vis: ast::Visibility, } -impl Copy for MethodInfo {} - pub fn get_symbol(cstore: &cstore::CStore, def: ast::DefId) -> String { let cdata = cstore.get_crate_data(def.krate); decoder::get_symbol(cdata.data(), def.node) diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index cede093fae696..d5247472c3447 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -48,23 +48,19 @@ pub struct crate_metadata { pub span: Span, } -#[deriving(Show, PartialEq, Clone)] +#[deriving(Copy, Show, PartialEq, Clone)] pub enum LinkagePreference { RequireDynamic, RequireStatic, } -impl Copy for LinkagePreference {} - -#[deriving(Clone, PartialEq, FromPrimitive)] +#[deriving(Copy, Clone, PartialEq, FromPrimitive)] pub enum NativeLibraryKind { NativeStatic, // native static library (.a archive) NativeFramework, // OSX-specific NativeUnknown, // default way to specify a dynamic library } -impl Copy for NativeLibraryKind {} - // Where a crate came from on the local filesystem. One of these two options // must be non-None. #[deriving(PartialEq, Clone)] diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 7f1df80da3c8f..b89c5dbcd0885 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -450,15 +450,13 @@ pub fn get_symbol(data: &[u8], id: ast::NodeId) -> String { } // Something that a name can resolve to. -#[deriving(Clone,Show)] +#[deriving(Copy, Clone, Show)] pub enum DefLike { DlDef(def::Def), DlImpl(ast::DefId), DlField } -impl Copy for DefLike {} - /// Iterates over the language items in the given crate. pub fn each_lang_item(cdata: Cmd, mut f: F) -> bool where F: FnMut(ast::NodeId, uint) -> bool, diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 507fb751303f9..0b859abc531c8 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -20,13 +20,12 @@ use std::os; use util::fs as myfs; +#[deriving(Copy)] pub enum FileMatch { FileMatches, FileDoesntMatch, } -impl Copy for FileMatch {} - // A module for searching for libraries // FIXME (#2658): I'm not happy how this module turned out. Should // probably just be folded into cstore. diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index f2a41c48d1203..9d3a2c1d66777 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -44,7 +44,7 @@ use syntax::parse::token; // def-id will depend on where it originated from. Therefore, the conversion // function is given an indicator of the source of the def-id. See // astencode.rs for more information. -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum DefIdSource { // Identifies a struct, trait, enum, etc. NominalType, @@ -62,7 +62,6 @@ pub enum DefIdSource { UnboxedClosureSource } -impl Copy for DefIdSource {} pub type conv_did<'a> = |source: DefIdSource, ast::DefId|: 'a -> ast::DefId; diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index 0e10155beb470..82bed2540317f 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -26,14 +26,13 @@ struct CFGBuilder<'a, 'tcx: 'a> { loop_scopes: Vec, } +#[deriving(Copy)] struct LoopScope { loop_id: ast::NodeId, // id of loop/while node continue_index: CFGIndex, // where to go on a `loop` break_index: CFGIndex, // where to go on a `break } -impl Copy for LoopScope {} - pub fn construct(tcx: &ty::ctxt, blk: &ast::Block) -> CFG { let mut graph = graph::Graph::new(); diff --git a/src/librustc/middle/cfg/mod.rs b/src/librustc/middle/cfg/mod.rs index bc512a73a4bd8..a74fff5630bfd 100644 --- a/src/librustc/middle/cfg/mod.rs +++ b/src/librustc/middle/cfg/mod.rs @@ -26,12 +26,11 @@ pub struct CFG { pub exit: CFGIndex, } +#[deriving(Copy)] pub struct CFGNodeData { pub id: ast::NodeId } -impl Copy for CFGNodeData {} - pub struct CFGEdgeData { pub exiting_scopes: Vec } diff --git a/src/librustc/middle/check_loop.rs b/src/librustc/middle/check_loop.rs index c4ad089d76e6e..cb454f94dc74c 100644 --- a/src/librustc/middle/check_loop.rs +++ b/src/librustc/middle/check_loop.rs @@ -16,20 +16,17 @@ use syntax::codemap::Span; use syntax::visit::Visitor; use syntax::visit; -#[deriving(Clone, PartialEq)] +#[deriving(Clone, Copy, PartialEq)] enum Context { Normal, Loop, Closure } -impl Copy for Context {} - +#[deriving(Copy)] struct CheckLoopVisitor<'a> { sess: &'a Session, cx: Context } -impl<'a> Copy for CheckLoopVisitor<'a> {} - pub fn check_crate(sess: &Session, krate: &ast::Crate) { visit::walk_crate(&mut CheckLoopVisitor { sess: sess, cx: Normal }, krate) } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 034bf3e840a89..79e776c330884 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -127,13 +127,12 @@ enum Usefulness { NotUseful } +#[deriving(Copy)] enum WitnessPreference { ConstructWitness, LeaveOutWitness } -impl Copy for WitnessPreference {} - impl<'a, 'tcx, 'v> Visitor<'v> for MatchCheckCtxt<'a, 'tcx> { fn visit_expr(&mut self, ex: &ast::Expr) { check_expr(self, ex); diff --git a/src/librustc/middle/check_static.rs b/src/librustc/middle/check_static.rs index af2be6e088dd5..21e94d69366d6 100644 --- a/src/librustc/middle/check_static.rs +++ b/src/librustc/middle/check_static.rs @@ -39,7 +39,7 @@ use syntax::visit::Visitor; use syntax::codemap::Span; use syntax::visit; -#[deriving(Eq, PartialEq)] +#[deriving(Copy, Eq, PartialEq)] enum Mode { InConstant, InStatic, @@ -47,8 +47,6 @@ enum Mode { InNothing, } -impl Copy for Mode {} - struct CheckStaticVisitor<'a, 'tcx: 'a> { tcx: &'a ty::ctxt<'tcx>, mode: Mode, diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index f0d52d1ac23d0..9b94335654734 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -62,14 +62,13 @@ use std::collections::hash_map::Vacant; // - Non-constants: everything else. // +#[deriving(Copy)] pub enum constness { integral_const, general_const, non_const } -impl Copy for constness {} - type constness_cache = DefIdMap; pub fn join(a: constness, b: constness) -> constness { diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 9373a5704b2b0..17ebd1b94a708 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -27,14 +27,12 @@ use syntax::visit; use syntax::print::{pp, pprust}; use util::nodemap::NodeMap; -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum EntryOrExit { Entry, Exit, } -impl Copy for EntryOrExit {} - #[deriving(Clone)] pub struct DataFlowContext<'a, 'tcx: 'a, O> { tcx: &'a ty::ctxt<'tcx>, diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs index 8573dc747bb07..20a0dbdc1eefa 100644 --- a/src/librustc/middle/def.rs +++ b/src/librustc/middle/def.rs @@ -15,7 +15,7 @@ use middle::subst::ParamSpace; use syntax::ast; use syntax::ast_util::local_def; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum Def { DefFn(ast::DefId, bool /* is_ctor */), DefStaticMethod(/* method */ ast::DefId, MethodProvenance), @@ -56,15 +56,13 @@ pub enum Def { DefMethod(ast::DefId /* method */, Option /* trait */, MethodProvenance), } -impl Copy for Def {} - -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum MethodProvenance { FromTrait(ast::DefId), FromImpl(ast::DefId), } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum TyParamProvenance { FromSelf(ast::DefId), FromParam(ast::DefId), @@ -81,8 +79,6 @@ impl MethodProvenance { } } -impl Copy for MethodProvenance {} - impl TyParamProvenance { pub fn def_id(&self) -> ast::DefId { match *self { @@ -92,8 +88,6 @@ impl TyParamProvenance { } } -impl Copy for TyParamProvenance {} - impl Def { pub fn def_id(&self) -> ast::DefId { match *self { diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index d16ce3ad678b3..0c0cba6e53e06 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -23,15 +23,13 @@ use syntax::codemap::Span; use syntax::visit; use syntax::visit::Visitor; -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] enum UnsafeContext { SafeContext, UnsafeFn, UnsafeBlock(ast::NodeId), } -impl Copy for UnsafeContext {} - fn type_is_unsafe_function(ty: Ty) -> bool { match ty.sty { ty::ty_bare_fn(ref f) => f.unsafety == ast::Unsafety::Unsafe, diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 901944cd0168e..abc3c8d0d8fa4 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -95,7 +95,7 @@ pub trait Delegate<'tcx> { mode: MutateMode); } -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub enum LoanCause { ClosureCapture(Span), AddrOf, @@ -107,26 +107,20 @@ pub enum LoanCause { MatchDiscriminant } -impl kinds::Copy for LoanCause {} - -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub enum ConsumeMode { Copy, // reference to x where x has a type that copies Move(MoveReason), // reference to x where x has a type that moves } -impl kinds::Copy for ConsumeMode {} - -#[deriving(PartialEq,Show)] +#[deriving(Copy, PartialEq, Show)] pub enum MoveReason { DirectRefMove, PatBindingMove, CaptureMove, } -impl kinds::Copy for MoveReason {} - -#[deriving(PartialEq,Show)] +#[deriving(Copy, PartialEq, Show)] pub enum MatchMode { NonBindingMatch, BorrowingMatch, @@ -134,8 +128,6 @@ pub enum MatchMode { MovingMatch, } -impl kinds::Copy for MatchMode {} - #[deriving(PartialEq,Show)] enum TrackMatchMode { Unknown, @@ -205,23 +197,20 @@ impl TrackMatchMode { } } -#[deriving(PartialEq,Show)] +#[deriving(Copy, PartialEq, Show)] pub enum MutateMode { Init, JustWrite, // x = y WriteAndRead, // x += y } -impl kinds::Copy for MutateMode {} - +#[deriving(Copy)] enum OverloadedCallType { FnOverloadedCall, FnMutOverloadedCall, FnOnceOverloadedCall, } -impl kinds::Copy for OverloadedCallType {} - impl OverloadedCallType { fn from_trait_id(tcx: &ty::ctxt, trait_id: ast::DefId) -> OverloadedCallType { diff --git a/src/librustc/middle/fast_reject.rs b/src/librustc/middle/fast_reject.rs index 5c0d4b4841ee3..297d6bcb03cb9 100644 --- a/src/librustc/middle/fast_reject.rs +++ b/src/librustc/middle/fast_reject.rs @@ -14,7 +14,7 @@ use syntax::ast; use self::SimplifiedType::*; /// See `simplify_type -#[deriving(Clone, PartialEq, Eq, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash)] pub enum SimplifiedType { BoolSimplifiedType, CharSimplifiedType, @@ -33,8 +33,6 @@ pub enum SimplifiedType { ParameterSimplifiedType, } -impl Copy for SimplifiedType {} - /// Tries to simplify a type by dropping type parameters, deref'ing away any reference types, etc. /// The idea is to get something simple that we can use to quickly decide if two types could unify /// during method lookup. diff --git a/src/librustc/middle/graph.rs b/src/librustc/middle/graph.rs index 4c03ed2a480ef..e73fcd93e0504 100644 --- a/src/librustc/middle/graph.rs +++ b/src/librustc/middle/graph.rs @@ -60,30 +60,24 @@ impl Show for Edge { } } -#[deriving(Clone, PartialEq, Show)] +#[deriving(Clone, Copy, PartialEq, Show)] pub struct NodeIndex(pub uint); #[allow(non_upper_case_globals)] pub const InvalidNodeIndex: NodeIndex = NodeIndex(uint::MAX); -impl Copy for NodeIndex {} - -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub struct EdgeIndex(pub uint); #[allow(non_upper_case_globals)] pub const InvalidEdgeIndex: EdgeIndex = EdgeIndex(uint::MAX); -impl Copy for EdgeIndex {} - // Use a private field here to guarantee no more instances are created: -#[deriving(Show)] +#[deriving(Copy, Show)] pub struct Direction { repr: uint } #[allow(non_upper_case_globals)] pub const Outgoing: Direction = Direction { repr: 0 }; #[allow(non_upper_case_globals)] pub const Incoming: Direction = Direction { repr: 1 }; -impl Copy for Direction {} - impl NodeIndex { fn get(&self) -> uint { let NodeIndex(v) = *self; v } /// Returns unique id (unique with respect to the graph holding associated node). diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs index f419f050cf594..25eadae5b92f1 100644 --- a/src/librustc/middle/infer/mod.rs +++ b/src/librustc/middle/infer/mod.rs @@ -97,7 +97,7 @@ pub type SkolemizationMap = FnvHashMap; /// Why did we require that the two types be related? /// /// See `error_reporting.rs` for more details -#[deriving(Clone, Show)] +#[deriving(Clone, Copy, Show)] pub enum TypeOrigin { // Not yet categorized in a better way Misc(Span), @@ -131,8 +131,6 @@ pub enum TypeOrigin { EquatePredicate(Span), } -impl Copy for TypeOrigin {} - /// See `error_reporting.rs` for more details #[deriving(Clone, Show)] pub enum ValuePairs<'tcx> { @@ -223,7 +221,7 @@ pub enum SubregionOrigin<'tcx> { } /// Times when we replace late-bound regions with variables: -#[deriving(Clone, Show)] +#[deriving(Clone, Copy, Show)] pub enum LateBoundRegionConversionTime { /// when a fn is called FnCall, @@ -232,8 +230,6 @@ pub enum LateBoundRegionConversionTime { HigherRankedType, } -impl Copy for LateBoundRegionConversionTime {} - /// Reasons to create a region inference variable /// /// See `error_reporting.rs` for more details @@ -270,15 +266,13 @@ pub enum RegionVariableOrigin<'tcx> { BoundRegionInCoherence(ast::Name), } -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum fixup_err { unresolved_int_ty(IntVid), unresolved_float_ty(FloatVid), unresolved_ty(TyVid) } -impl Copy for fixup_err {} - pub fn fixup_err_to_string(f: fixup_err) -> String { match f { unresolved_int_ty(_) => { diff --git a/src/librustc/middle/infer/region_inference/mod.rs b/src/librustc/middle/infer/region_inference/mod.rs index d34373e66a1e0..bcaf39cc8dbd1 100644 --- a/src/librustc/middle/infer/region_inference/mod.rs +++ b/src/librustc/middle/infer/region_inference/mod.rs @@ -40,7 +40,7 @@ mod doc; mod graphviz; // A constraint that influences the inference process. -#[deriving(Clone, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub enum Constraint { // One region variable is subregion of another ConstrainVarSubVar(RegionVid, RegionVid), @@ -52,8 +52,6 @@ pub enum Constraint { ConstrainVarSubReg(RegionVid, Region), } -impl Copy for Constraint {} - // Something we have to verify after region inference is done, but // which does not directly influence the inference process pub enum Verify<'tcx> { @@ -69,15 +67,13 @@ pub enum Verify<'tcx> { VerifyParamBound(ty::ParamTy, SubregionOrigin<'tcx>, Region, Vec), } -#[deriving(PartialEq, Eq, Hash)] +#[deriving(Copy, PartialEq, Eq, Hash)] pub struct TwoRegions { a: Region, b: Region, } -impl Copy for TwoRegions {} - -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum UndoLogEntry { OpenSnapshot, CommitedSnapshot, @@ -88,15 +84,11 @@ pub enum UndoLogEntry { AddCombination(CombineMapType, TwoRegions) } -impl Copy for UndoLogEntry {} - -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum CombineMapType { Lub, Glb } -impl Copy for CombineMapType {} - #[deriving(Clone, Show)] pub enum RegionResolutionError<'tcx> { /// `ConcreteFailure(o, a, b)`: @@ -940,15 +932,12 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { // ______________________________________________________________________ -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] enum Classification { Expanding, Contracting } -impl Copy for Classification {} - +#[deriving(Copy)] pub enum VarValue { NoValue, Value(Region), ErrorValue } -impl Copy for VarValue {} - struct VarData { classification: Classification, value: VarValue, diff --git a/src/librustc/middle/infer/type_variable.rs b/src/librustc/middle/infer/type_variable.rs index 0d7f542535c2f..5e857154871ea 100644 --- a/src/librustc/middle/infer/type_variable.rs +++ b/src/librustc/middle/infer/type_variable.rs @@ -46,13 +46,11 @@ struct Delegate; type Relation = (RelationDir, ty::TyVid); -#[deriving(PartialEq,Show)] +#[deriving(Copy, PartialEq, Show)] pub enum RelationDir { SubtypeOf, SupertypeOf, EqTo } -impl Copy for RelationDir {} - impl RelationDir { fn opposite(self) -> RelationDir { match self { diff --git a/src/librustc/middle/infer/unify.rs b/src/librustc/middle/infer/unify.rs index a2dd4d6291352..0b81823e9ed1a 100644 --- a/src/librustc/middle/infer/unify.rs +++ b/src/librustc/middle/infer/unify.rs @@ -90,10 +90,9 @@ pub struct Node { pub rank: uint, } +#[deriving(Copy)] pub struct Delegate; -impl Copy for Delegate {} - // We can't use V:LatticeValue, much as I would like to, // because frequently the pattern is that V=Option for some // other type parameter U, and we have no way to say diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 8d5528b3709ad..2ffc5d8a510a3 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -45,13 +45,11 @@ macro_rules! lets_do_this { $( $variant:ident, $name:expr, $method:ident; )* ) => { -#[deriving(FromPrimitive, PartialEq, Eq, Hash)] +#[deriving(Copy, FromPrimitive, PartialEq, Eq, Hash)] pub enum LangItem { $($variant),* } -impl Copy for LangItem {} - pub struct LanguageItems { pub items: Vec>, pub missing: Vec, diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 4df655882b155..b76d798941ef9 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -135,16 +135,12 @@ enum LoopKind<'a> { ForLoop(&'a ast::Pat), } -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] struct Variable(uint); -impl Copy for Variable {} - -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] struct LiveNode(uint); -impl Copy for LiveNode {} - impl Variable { fn get(&self) -> uint { let Variable(v) = *self; v } } @@ -159,7 +155,7 @@ impl Clone for LiveNode { } } -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] enum LiveNodeKind { FreeVarNode(Span), ExprNode(Span), @@ -167,8 +163,6 @@ enum LiveNodeKind { ExitNode } -impl Copy for LiveNodeKind {} - fn live_node_kind_to_string(lnk: LiveNodeKind, cx: &ty::ctxt) -> String { let cm = cx.sess.codemap(); match lnk { @@ -247,15 +241,13 @@ struct CaptureInfo { var_nid: NodeId } -#[deriving(Show)] +#[deriving(Copy, Show)] struct LocalInfo { id: NodeId, ident: ast::Ident } -impl Copy for LocalInfo {} - -#[deriving(Show)] +#[deriving(Copy, Show)] enum VarKind { Arg(NodeId, ast::Ident), Local(LocalInfo), @@ -263,8 +255,6 @@ enum VarKind { CleanExit } -impl Copy for VarKind {} - struct IrMaps<'a, 'tcx: 'a> { tcx: &'a ty::ctxt<'tcx>, @@ -536,15 +526,13 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) { // Actually we compute just a bit more than just liveness, but we use // the same basic propagation framework in all cases. -#[deriving(Clone)] +#[deriving(Clone, Copy)] struct Users { reader: LiveNode, writer: LiveNode, used: bool } -impl Copy for Users {} - fn invalid_users() -> Users { Users { reader: invalid_node(), @@ -553,6 +541,7 @@ fn invalid_users() -> Users { } } +#[deriving(Copy)] struct Specials { exit_ln: LiveNode, fallthrough_ln: LiveNode, @@ -560,8 +549,6 @@ struct Specials { clean_exit_var: Variable } -impl Copy for Specials {} - static ACC_READ: uint = 1u; static ACC_WRITE: uint = 2u; static ACC_USE: uint = 4u; diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 0e05eb4dcdd9a..dce75579ca0a2 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -101,7 +101,7 @@ pub enum categorization<'tcx> { } // Represents any kind of upvar -#[deriving(Clone, PartialEq, Show)] +#[deriving(Clone, Copy, PartialEq, Show)] pub struct Upvar { pub id: ty::UpvarId, // Unboxed closure kinds are used even for old-style closures for simplicity @@ -110,10 +110,8 @@ pub struct Upvar { pub is_unboxed: bool } -impl Copy for Upvar {} - // different kinds of pointers: -#[deriving(Clone, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub enum PointerKind { OwnedPtr, BorrowedPtr(ty::BorrowKind, ty::Region), @@ -121,57 +119,45 @@ pub enum PointerKind { UnsafePtr(ast::Mutability) } -impl Copy for PointerKind {} - // We use the term "interior" to mean "something reachable from the // base without a pointer dereference", e.g. a field -#[deriving(Clone, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub enum InteriorKind { InteriorField(FieldName), InteriorElement(ElementKind), } -impl Copy for InteriorKind {} - -#[deriving(Clone, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub enum FieldName { NamedField(ast::Name), PositionalField(uint) } -impl Copy for FieldName {} - -#[deriving(Clone, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub enum ElementKind { VecElement, OtherElement, } -impl Copy for ElementKind {} - -#[deriving(Clone, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub enum MutabilityCategory { McImmutable, // Immutable. McDeclared, // Directly declared as mutable. McInherited, // Inherited from the fact that owner is mutable. } -impl Copy for MutabilityCategory {} - // A note about the provenance of a `cmt`. This is used for // special-case handling of upvars such as mutability inference. // Upvar categorization can generate a variable number of nested // derefs. The note allows detecting them without deep pattern // matching on the categorization. -#[deriving(Clone, PartialEq, Show)] +#[deriving(Clone, Copy, PartialEq, Show)] pub enum Note { NoteClosureEnv(ty::UpvarId), // Deref through closure env NoteUpvarRef(ty::UpvarId), // Deref through by-ref upvar NoteNone // Nothing special } -impl Copy for Note {} - // `cmt`: "Category, Mutability, and Type". // // a complete categorization of a value indicating where it originated @@ -200,13 +186,12 @@ pub type cmt<'tcx> = Rc>; // We pun on *T to mean both actual deref of a ptr as well // as accessing of components: +#[deriving(Copy)] pub enum deref_kind { deref_ptr(PointerKind), deref_interior(InteriorKind), } -impl Copy for deref_kind {} - // Categorizes a derefable type. Note that we include vectors and strings as // derefable (we model an index as the combination of a deref and then a // pointer adjustment). @@ -1394,13 +1379,13 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { } } +#[deriving(Copy)] pub enum InteriorSafety { InteriorUnsafe, InteriorSafe } -impl Copy for InteriorSafety {} - +#[deriving(Copy)] pub enum AliasableReason { AliasableBorrowed, AliasableClosure(ast::NodeId), // Aliasable due to capture Fn closure env @@ -1409,8 +1394,6 @@ pub enum AliasableReason { AliasableStaticMut(InteriorSafety), } -impl Copy for AliasableReason {} - impl<'tcx> cmt_<'tcx> { pub fn guarantor(&self) -> cmt<'tcx> { //! Returns `self` after stripping away any owned pointer derefs or diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 390729df0125d..e0d5a3a50e612 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -36,13 +36,11 @@ use syntax::visit::{Visitor, FnKind}; /// placate the same deriving in `ty::FreeRegion`, but we may want to /// actually attach a more meaningful ordering to scopes than the one /// generated via deriving here. -#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] pub enum CodeExtent { Misc(ast::NodeId) } -impl Copy for CodeExtent {} - impl CodeExtent { /// Creates a scope that represents the dynamic extent associated /// with `node_id`. @@ -117,6 +115,7 @@ pub struct RegionMaps { terminating_scopes: RefCell>, } +#[deriving(Copy)] pub struct Context { var_parent: Option, @@ -124,8 +123,6 @@ pub struct Context { parent: Option, } -impl Copy for Context {} - struct RegionResolutionVisitor<'a> { sess: &'a Session, diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 734453db693ec..e1e376c537cba 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -89,13 +89,12 @@ use std::uint; // Definition mapping pub type DefMap = RefCell>; +#[deriving(Copy)] struct binding_info { span: Span, binding_mode: BindingMode, } -impl Copy for binding_info {} - // Map from the name in a pattern to its binding mode. type BindingMap = HashMap; @@ -118,7 +117,7 @@ pub type ExternalExports = DefIdSet; // FIXME: dox pub type LastPrivateMap = NodeMap; -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum LastPrivate { LastMod(PrivateDep), // `use` directives (imports) can refer to two separate definitions in the @@ -132,25 +131,19 @@ pub enum LastPrivate { type_used: ImportUse}, } -impl Copy for LastPrivate {} - -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum PrivateDep { AllPublic, DependsOn(DefId), } -impl Copy for PrivateDep {} - // How an import is used. -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub enum ImportUse { Unused, // The import is not used. Used, // The import is used. } -impl Copy for ImportUse {} - impl LastPrivate { fn or(self, other: LastPrivate) -> LastPrivate { match (self, other) { @@ -160,24 +153,20 @@ impl LastPrivate { } } -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] enum PatternBindingMode { RefutableMode, LocalIrrefutableMode, ArgumentIrrefutableMode, } -impl Copy for PatternBindingMode {} - -#[deriving(PartialEq, Eq, Hash, Show)] +#[deriving(Copy, PartialEq, Eq, Hash, Show)] enum Namespace { TypeNS, ValueNS } -impl Copy for Namespace {} - -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] enum NamespaceError { NoError, ModuleError, @@ -185,8 +174,6 @@ enum NamespaceError { ValueError } -impl Copy for NamespaceError {} - /// A NamespaceResult represents the result of resolving an import in /// a particular namespace. The result is either definitely-resolved, /// definitely- unresolved, or unknown. @@ -247,13 +234,12 @@ impl<'a, 'v> Visitor<'v> for Resolver<'a> { } /// Contains data for specific types of import directives. +#[deriving(Copy)] enum ImportDirectiveSubclass { SingleImport(Name /* target */, Name /* source */), GlobImport } -impl Copy for ImportDirectiveSubclass {} - /// The context that we thread through while building the reduced graph. #[deriving(Clone)] enum ReducedGraphParent { @@ -293,6 +279,7 @@ enum FallbackSuggestion { TraitMethod(String), } +#[deriving(Copy)] enum TypeParameters<'a> { NoTypeParameters, HasTypeParameters( @@ -310,11 +297,9 @@ enum TypeParameters<'a> { RibKind) } -impl<'a> Copy for TypeParameters<'a> {} - // The rib kind controls the translation of local // definitions (`DefLocal`) to upvars (`DefUpvar`). -#[deriving(Show)] +#[deriving(Copy, Show)] enum RibKind { // No translation needs to be applied. NormalRibKind, @@ -337,38 +322,31 @@ enum RibKind { ConstantItemRibKind } -impl Copy for RibKind {} - // Methods can be required or provided. RequiredMethod methods only occur in traits. -#[deriving(Show)] +#[deriving(Copy, Show)] enum MethodSort { RequiredMethod, ProvidedMethod(NodeId) } -impl Copy for MethodSort {} - +#[deriving(Copy)] enum UseLexicalScopeFlag { DontUseLexicalScope, UseLexicalScope } -impl Copy for UseLexicalScopeFlag {} - enum ModulePrefixResult { NoPrefixFound, PrefixFound(Rc, uint) } -#[deriving(Clone, Eq, PartialEq)] +#[deriving(Clone, Copy, Eq, PartialEq)] pub enum TraitItemKind { NonstaticMethodTraitItemKind, StaticMethodTraitItemKind, TypeTraitItemKind, } -impl Copy for TraitItemKind {} - impl TraitItemKind { pub fn from_explicit_self_category(explicit_self_category: ExplicitSelfCategory) @@ -381,7 +359,7 @@ impl TraitItemKind { } } -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] enum NameSearchType { /// We're doing a name search in order to resolve a `use` directive. ImportSearch, @@ -391,19 +369,16 @@ enum NameSearchType { PathSearch, } -impl Copy for NameSearchType {} - +#[deriving(Copy)] enum BareIdentifierPatternResolution { FoundStructOrEnumVariant(Def, LastPrivate), FoundConst(Def, LastPrivate), BareIdentifierPatternUnresolved } -impl Copy for BareIdentifierPatternResolution {} - // Specifies how duplicates should be handled when adding a child item if // another item exists with the same name in some namespace. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] enum DuplicateCheckingMode { ForbidDuplicateModules, ForbidDuplicateTypesAndModules, @@ -412,8 +387,6 @@ enum DuplicateCheckingMode { OverwriteDuplicates } -impl Copy for DuplicateCheckingMode {} - /// One local scope. #[deriving(Show)] struct Rib { @@ -543,7 +516,7 @@ enum ParentLink { } /// The type of module this is. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] enum ModuleKind { NormalModuleKind, TraitModuleKind, @@ -552,8 +525,6 @@ enum ModuleKind { AnonymousModuleKind, } -impl Copy for ModuleKind {} - /// One node in the tree of modules. struct Module { parent_link: ParentLink, @@ -645,15 +616,13 @@ struct TypeNsDef { } // Records a possibly-private value definition. -#[deriving(Clone, Show)] +#[deriving(Clone, Copy, Show)] struct ValueNsDef { modifiers: DefModifiers, // see note in ImportResolution about how to use this def: Def, value_span: Option, } -impl Copy for ValueNsDef {} - // Records the definitions (at most one for each namespace) that a name is // bound to. struct NameBindings { @@ -662,6 +631,7 @@ struct NameBindings { } /// Ways in which a trait can be referenced +#[deriving(Copy)] enum TraitReferenceType { TraitImplementation, // impl SomeTrait for T { ... } TraitDerivation, // trait T : SomeTrait { ... } @@ -670,8 +640,6 @@ enum TraitReferenceType { TraitQPath, // :: } -impl Copy for TraitReferenceType {} - impl NameBindings { fn new() -> NameBindings { NameBindings { diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 33701905aa110..2202137d14936 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -34,7 +34,7 @@ use syntax::visit; use syntax::visit::Visitor; use util::nodemap::NodeMap; -#[deriving(Clone, PartialEq, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)] pub enum DefRegion { DefStaticRegion, DefEarlyBoundRegion(/* space */ subst::ParamSpace, @@ -46,8 +46,6 @@ pub enum DefRegion { /* lifetime decl */ ast::NodeId), } -impl Copy for DefRegion {} - // maps the id of each lifetime reference to the lifetime decl // that it corresponds to pub type NamedRegionMap = NodeMap; diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index 1cf25cd1dc866..30a47ff913258 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -187,7 +187,7 @@ impl RegionSubsts { /////////////////////////////////////////////////////////////////////////// // ParamSpace -#[deriving(PartialOrd, Ord, PartialEq, Eq, +#[deriving(Copy, PartialOrd, Ord, PartialEq, Eq, Clone, Hash, Encodable, Decodable, Show)] pub enum ParamSpace { TypeSpace, // Type parameters attached to a type definition, trait, or impl @@ -196,8 +196,6 @@ pub enum ParamSpace { FnSpace, // Type parameters attached to a method or fn } -impl Copy for ParamSpace {} - impl ParamSpace { pub fn all() -> [ParamSpace, ..4] { [TypeSpace, SelfSpace, AssocSpace, FnSpace] diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 6c7ae666ae06c..8ba28b61006bd 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -91,7 +91,7 @@ pub enum MethodMatchResult { MethodDidNotMatch, } -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum MethodMatchedData { // In the case of a precise match, we don't really need to store // how the match was found. So don't. @@ -102,8 +102,6 @@ pub enum MethodMatchedData { CoerciveMethodMatch(/* impl we matched */ ast::DefId) } -impl Copy for MethodMatchedData {} - /// The selection process begins by considering all impls, where /// clauses, and so forth that might resolve an obligation. Sometimes /// we'll be able to say definitively that (e.g.) an impl does not diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 6839e8bcc45db..acf1fced72cae 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -107,22 +107,18 @@ pub struct CrateAnalysis<'tcx> { pub name: String, } -#[deriving(PartialEq, Eq, Hash)] +#[deriving(Copy, PartialEq, Eq, Hash)] pub struct field<'tcx> { pub name: ast::Name, pub mt: mt<'tcx> } -impl<'tcx> Copy for field<'tcx> {} - -#[deriving(Clone, Show)] +#[deriving(Clone, Copy, Show)] pub enum ImplOrTraitItemContainer { TraitContainer(ast::DefId), ImplContainer(ast::DefId), } -impl Copy for ImplOrTraitItemContainer {} - impl ImplOrTraitItemContainer { pub fn id(&self) -> ast::DefId { match *self { @@ -177,14 +173,12 @@ impl<'tcx> ImplOrTraitItem<'tcx> { } } -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub enum ImplOrTraitItemId { MethodTraitItemId(ast::DefId), TypeTraitItemId(ast::DefId), } -impl Copy for ImplOrTraitItemId {} - impl ImplOrTraitItemId { pub fn def_id(&self) -> ast::DefId { match *self { @@ -238,7 +232,7 @@ impl<'tcx> Method<'tcx> { } } -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct AssociatedType { pub name: ast::Name, pub vis: ast::Visibility, @@ -246,17 +240,13 @@ pub struct AssociatedType { pub container: ImplOrTraitItemContainer, } -impl Copy for AssociatedType {} - -#[deriving(Clone, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub struct mt<'tcx> { pub ty: Ty<'tcx>, pub mutbl: ast::Mutability, } -impl<'tcx> Copy for mt<'tcx> {} - -#[deriving(Clone, PartialEq, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)] pub enum TraitStore { /// Box UniqTraitStore, @@ -264,9 +254,7 @@ pub enum TraitStore { RegionTraitStore(Region, ast::Mutability), } -impl Copy for TraitStore {} - -#[deriving(Clone, Show)] +#[deriving(Clone, Copy, Show)] pub struct field_ty { pub name: Name, pub id: DefId, @@ -274,33 +262,28 @@ pub struct field_ty { pub origin: ast::DefId, // The DefId of the struct in which the field is declared. } -impl Copy for field_ty {} - // Contains information needed to resolve types and (in the future) look up // the types of AST nodes. -#[deriving(PartialEq, Eq, Hash)] +#[deriving(Copy, PartialEq, Eq, Hash)] pub struct creader_cache_key { pub cnum: CrateNum, pub pos: uint, pub len: uint } -impl Copy for creader_cache_key {} - +#[deriving(Copy)] pub enum ast_ty_to_ty_cache_entry<'tcx> { atttce_unresolved, /* not resolved yet */ atttce_resolved(Ty<'tcx>) /* resolved to a type, irrespective of region */ } -impl<'tcx> Copy for ast_ty_to_ty_cache_entry<'tcx> {} - #[deriving(Clone, PartialEq, Decodable, Encodable)] pub struct ItemVariances { pub types: VecPerParamSpace, pub regions: VecPerParamSpace, } -#[deriving(Clone, PartialEq, Decodable, Encodable, Show)] +#[deriving(Clone, Copy, PartialEq, Decodable, Encodable, Show)] pub enum Variance { Covariant, // T <: T iff A <: B -- e.g., function return type Invariant, // T <: T iff B == A -- e.g., type of mutable cell @@ -308,8 +291,6 @@ pub enum Variance { Bivariant, // T <: T -- e.g., unused type parameter } -impl Copy for Variance {} - #[deriving(Clone, Show)] pub enum AutoAdjustment<'tcx> { AdjustAddEnv(ty::TraitStore), @@ -449,14 +430,12 @@ pub fn type_of_adjust<'tcx>(cx: &ctxt<'tcx>, adj: &AutoAdjustment<'tcx>) -> Opti } } -#[deriving(Clone, Encodable, Decodable, PartialEq, PartialOrd, Show)] +#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, PartialOrd, Show)] pub struct param_index { pub space: subst::ParamSpace, pub index: uint } -impl Copy for param_index {} - #[deriving(Clone, Show)] pub enum MethodOrigin<'tcx> { // fully statically resolved method @@ -513,8 +492,6 @@ pub struct MethodCallee<'tcx> { pub substs: subst::Substs<'tcx> } -impl Copy for MethodCall {} - /// With method calls, we store some extra information in /// side tables (i.e method_map). We use /// MethodCall as a key to index into these tables instead of @@ -527,21 +504,19 @@ impl Copy for MethodCall {} /// needed to add to the side tables. Thus to disambiguate /// we also keep track of whether there's an adjustment in /// our key. -#[deriving(Clone, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub struct MethodCall { pub expr_id: ast::NodeId, pub adjustment: ExprAdjustment } -#[deriving(Clone, PartialEq, Eq, Hash, Show, Encodable, Decodable)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show, Encodable, Decodable)] pub enum ExprAdjustment { NoAdjustment, AutoDeref(uint), AutoObject } -impl Copy for ExprAdjustment {} - impl MethodCall { pub fn expr(id: ast::NodeId) -> MethodCall { MethodCall { @@ -615,6 +590,7 @@ pub type ObjectCastMap<'tcx> = RefCell>>>; /// A restriction that certain types must be the same size. The use of /// `transmute` gives rise to these restrictions. +#[deriving(Copy)] pub struct TransmuteRestriction<'tcx> { /// The span from whence the restriction comes. pub span: Span, @@ -626,8 +602,6 @@ pub struct TransmuteRestriction<'tcx> { pub id: ast::NodeId, } -impl<'tcx> Copy for TransmuteRestriction<'tcx> {} - /// The data structure to keep track of all the information that typechecker /// generates so that so that it can be reused and doesn't have to be redone /// later on. @@ -923,7 +897,7 @@ pub struct ClosureTy<'tcx> { pub abi: abi::Abi, } -#[deriving(Clone, PartialEq, Eq, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash)] pub enum FnOutput<'tcx> { FnConverging(Ty<'tcx>), FnDiverging @@ -938,8 +912,6 @@ impl<'tcx> FnOutput<'tcx> { } } -impl<'tcx> Copy for FnOutput<'tcx> {} - /// Signature of a function type, which I have arbitrarily /// decided to use to refer to the input/output types. /// @@ -955,15 +927,13 @@ pub struct FnSig<'tcx> { pub type PolyFnSig<'tcx> = Binder>; -#[deriving(Clone, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub struct ParamTy { pub space: subst::ParamSpace, pub idx: uint, pub def_id: DefId } -impl Copy for ParamTy {} - /// A [De Bruijn index][dbi] is a standard means of representing /// regions (and perhaps later types) in a higher-ranked setting. In /// particular, imagine a type like this: @@ -1003,7 +973,7 @@ impl Copy for ParamTy {} /// is the outer fn. /// /// [dbi]: http://en.wikipedia.org/wiki/De_Bruijn_index -#[deriving(Clone, PartialEq, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)] pub struct DebruijnIndex { // We maintain the invariant that this is never 0. So 1 indicates // the innermost binder. To ensure this, create with `DebruijnIndex::new`. @@ -1011,7 +981,7 @@ pub struct DebruijnIndex { } /// Representation of regions: -#[deriving(Clone, PartialEq, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)] pub enum Region { // Region bound in a type or fn declaration which will be // substituted 'early' -- that is, at the same time when type @@ -1052,15 +1022,13 @@ pub enum Region { /// Upvars do not get their own node-id. Instead, we use the pair of /// the original var id (that is, the root variable that is referenced /// by the upvar) and the id of the closure expression. -#[deriving(Clone, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub struct UpvarId { pub var_id: ast::NodeId, pub closure_expr_id: ast::NodeId, } -impl Copy for UpvarId {} - -#[deriving(Clone, PartialEq, Eq, Hash, Show, Encodable, Decodable)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show, Encodable, Decodable)] pub enum BorrowKind { /// Data must be immutable and is aliasable. ImmBorrow, @@ -1106,8 +1074,6 @@ pub enum BorrowKind { MutBorrow } -impl Copy for BorrowKind {} - /// Information describing the borrowing of an upvar. This is computed /// during `typeck`, specifically by `regionck`. The general idea is /// that the compiler analyses treat closures like: @@ -1155,7 +1121,7 @@ impl Copy for BorrowKind {} /// - Through mutation, the borrowed upvars can actually escape /// the closure, so sometimes it is necessary for them to be larger /// than the closure lifetime itself. -#[deriving(PartialEq, Clone, Encodable, Decodable, Show)] +#[deriving(Copy, PartialEq, Clone, Encodable, Decodable, Show)] pub struct UpvarBorrow { pub kind: BorrowKind, pub region: ty::Region, @@ -1163,8 +1129,6 @@ pub struct UpvarBorrow { pub type UpvarBorrowMap = FnvHashMap; -impl Copy for UpvarBorrow {} - impl Region { pub fn is_bound(&self) -> bool { match *self { @@ -1182,9 +1146,7 @@ impl Region { } } -impl Copy for Region {} - -#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] /// A "free" region `fr` can be interpreted as "some region /// at least as big as the scope `fr.scope`". pub struct FreeRegion { @@ -1192,9 +1154,7 @@ pub struct FreeRegion { pub bound_region: BoundRegion } -impl Copy for FreeRegion {} - -#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] pub enum BoundRegion { /// An anonymous region parameter for a given fn (&T) BrAnon(uint), @@ -1213,8 +1173,6 @@ pub enum BoundRegion { BrEnv } -impl Copy for BoundRegion {} - #[inline] pub fn mk_prim_t<'tcx>(primitive: &'tcx TyS<'static>) -> Ty<'tcx> { // FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx. @@ -1378,15 +1336,13 @@ impl<'tcx> PolyTraitRef<'tcx> { #[deriving(Clone, PartialEq, Eq, Hash, Show)] pub struct Binder(pub T); -#[deriving(Clone, PartialEq)] +#[deriving(Clone, Copy, PartialEq)] pub enum IntVarValue { IntType(ast::IntTy), UintType(ast::UintTy), } -impl Copy for IntVarValue {} - -#[deriving(Clone, Show)] +#[deriving(Clone, Copy, Show)] pub enum terr_vstore_kind { terr_vec, terr_str, @@ -1394,18 +1350,14 @@ pub enum terr_vstore_kind { terr_trait } -impl Copy for terr_vstore_kind {} - -#[deriving(Clone, Show)] +#[deriving(Clone, Copy, Show)] pub struct expected_found { pub expected: T, pub found: T } -impl Copy for expected_found {} - // Data structures used in type unification -#[deriving(Clone, Show)] +#[deriving(Clone, Copy, Show)] pub enum type_err<'tcx> { terr_mismatch, terr_unsafety_mismatch(expected_found), @@ -1438,8 +1390,6 @@ pub enum type_err<'tcx> { terr_convergence_mismatch(expected_found) } -impl<'tcx> Copy for type_err<'tcx> {} - /// Bounds suitable for a named type parameter like `A` in `fn foo` /// as well as the existential type parameter in an object type. #[deriving(PartialEq, Eq, Hash, Clone, Show)] @@ -1454,17 +1404,15 @@ pub struct ParamBounds<'tcx> { /// major difference between this case and `ParamBounds` is that /// general purpose trait bounds are omitted and there must be /// *exactly one* region. -#[deriving(PartialEq, Eq, Hash, Clone, Show)] +#[deriving(Copy, PartialEq, Eq, Hash, Clone, Show)] pub struct ExistentialBounds { pub region_bound: ty::Region, pub builtin_bounds: BuiltinBounds } -impl Copy for ExistentialBounds {} - pub type BuiltinBounds = EnumSet; -#[deriving(Clone, Encodable, PartialEq, Eq, Decodable, Hash, Show)] +#[deriving(Copy, Clone, Encodable, PartialEq, Eq, Decodable, Hash, Show)] #[repr(uint)] pub enum BuiltinBound { BoundSend, @@ -1473,8 +1421,6 @@ pub enum BuiltinBound { BoundSync, } -impl Copy for BuiltinBound {} - pub fn empty_builtin_bounds() -> BuiltinBounds { EnumSet::new() } @@ -1502,35 +1448,27 @@ impl CLike for BuiltinBound { } } -#[deriving(Clone, PartialEq, Eq, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash)] pub struct TyVid { pub index: uint } -impl Copy for TyVid {} - -#[deriving(Clone, PartialEq, Eq, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash)] pub struct IntVid { pub index: uint } -impl Copy for IntVid {} - -#[deriving(Clone, PartialEq, Eq, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash)] pub struct FloatVid { pub index: uint } -impl Copy for FloatVid {} - -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)] pub struct RegionVid { pub index: uint } -impl Copy for RegionVid {} - -#[deriving(Clone, PartialEq, Eq, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash)] pub enum InferTy { TyVar(TyVid), IntVar(IntVid), @@ -1547,16 +1485,12 @@ pub enum InferTy { FreshIntTy(uint), } -impl Copy for InferTy {} - -#[deriving(Clone, Encodable, Decodable, Eq, Hash, Show)] +#[deriving(Clone, Copy, Encodable, Decodable, Eq, Hash, Show)] pub enum InferRegion { ReVar(RegionVid), ReSkolemized(uint, BoundRegion) } -impl Copy for InferRegion {} - impl cmp::PartialEq for InferRegion { fn eq(&self, other: &InferRegion) -> bool { match ((*self), *other) { @@ -2006,15 +1940,13 @@ pub struct UnboxedClosure<'tcx> { pub kind: UnboxedClosureKind, } -#[deriving(Clone, PartialEq, Eq, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Show)] pub enum UnboxedClosureKind { FnUnboxedClosureKind, FnMutUnboxedClosureKind, FnOnceUnboxedClosureKind, } -impl Copy for UnboxedClosureKind {} - impl UnboxedClosureKind { pub fn trait_did(&self, cx: &ctxt) -> ast::DefId { let result = match *self { @@ -2795,13 +2727,11 @@ pub fn type_needs_unwind_cleanup<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { /// The reason we compute type contents and not kinds is that it is /// easier for me (nmatsakis) to think about what is contained within /// a type than to think about what is *not* contained within a type. -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct TypeContents { pub bits: u64 } -impl Copy for TypeContents {} - macro_rules! def_type_content_sets { (mod $mname:ident { $($name:ident = $bits:expr),+ }) => { #[allow(non_snake_case)] @@ -3443,15 +3373,13 @@ pub fn is_instantiable<'tcx>(cx: &ctxt<'tcx>, r_ty: Ty<'tcx>) -> bool { /// /// The ordering of the cases is significant. They are sorted so that cmp::max /// will keep the "more erroneous" of two values. -#[deriving(PartialOrd, Ord, Eq, PartialEq, Show)] +#[deriving(Copy, PartialOrd, Ord, Eq, PartialEq, Show)] pub enum Representability { Representable, ContainsRecursive, SelfRecursive, } -impl Copy for Representability {} - /// Check whether a type is representable. This means it cannot contain unboxed /// structural recursion. This check is needed for structs and enums. pub fn is_type_representable<'tcx>(cx: &ctxt<'tcx>, sp: Span, ty: Ty<'tcx>) @@ -4228,6 +4156,7 @@ pub fn expr_is_lval(tcx: &ctxt, e: &ast::Expr) -> bool { /// two kinds of rvalues is an artifact of trans which reflects how we will /// generate code for that kind of expression. See trans/expr.rs for more /// information. +#[deriving(Copy)] pub enum ExprKind { LvalueExpr, RvalueDpsExpr, @@ -4235,8 +4164,6 @@ pub enum ExprKind { RvalueStmtExpr } -impl Copy for ExprKind {} - pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { if tcx.method_map.borrow().contains_key(&MethodCall::expr(expr.id)) { // Overloaded operations are generally calls, and hence they are @@ -4791,15 +4718,13 @@ pub fn associated_type_parameter_index(cx: &ctxt, cx.sess.bug("couldn't find associated type parameter index") } -#[deriving(PartialEq, Eq)] +#[deriving(Copy, PartialEq, Eq)] pub struct AssociatedTypeInfo { pub def_id: ast::DefId, pub index: uint, pub name: ast::Name, } -impl Copy for AssociatedTypeInfo {} - impl PartialOrd for AssociatedTypeInfo { fn partial_cmp(&self, other: &AssociatedTypeInfo) -> Option { Some(self.index.cmp(&other.index)) @@ -4979,13 +4904,12 @@ pub fn item_path_str(cx: &ctxt, id: ast::DefId) -> String { with_path(cx, id, |path| ast_map::path_to_string(path)).to_string() } +#[deriving(Copy)] pub enum DtorKind { NoDtor, TraitDtor(DefId, bool) } -impl Copy for DtorKind {} - impl DtorKind { pub fn is_present(&self) -> bool { match *self { @@ -5403,14 +5327,13 @@ pub fn tup_fields<'tcx>(v: &[Ty<'tcx>]) -> Vec> { }).collect() } +#[deriving(Copy)] pub struct UnboxedClosureUpvar<'tcx> { pub def: def::Def, pub span: Span, pub ty: Ty<'tcx>, } -impl<'tcx> Copy for UnboxedClosureUpvar<'tcx> {} - // Returns a list of `UnboxedClosureUpvar`s for each upvar. pub fn unboxed_closure_upvars<'tcx>(tcx: &ctxt<'tcx>, closure_id: ast::DefId, substs: &Substs<'tcx>) -> Vec> { @@ -6259,7 +6182,7 @@ impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> { } /// The category of explicit self. -#[deriving(Clone, Eq, PartialEq, Show)] +#[deriving(Clone, Copy, Eq, PartialEq, Show)] pub enum ExplicitSelfCategory { StaticExplicitSelfCategory, ByValueExplicitSelfCategory, @@ -6267,8 +6190,6 @@ pub enum ExplicitSelfCategory { ByBoxExplicitSelfCategory, } -impl Copy for ExplicitSelfCategory {} - /// Pushes all the lifetimes in the given type onto the given list. A /// "lifetime in a type" is a lifetime specified by a reference or a lifetime /// in a list of type substitutions. This does *not* traverse into nominal @@ -6329,7 +6250,7 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec, } /// A free variable referred to in a function. -#[deriving(Encodable, Decodable)] +#[deriving(Copy, Encodable, Decodable)] pub struct Freevar { /// The variable being accessed free. pub def: def::Def, @@ -6338,8 +6259,6 @@ pub struct Freevar { pub span: Span } -impl Copy for Freevar {} - pub type FreevarMap = NodeMap>; pub type CaptureModeMap = NodeMap; @@ -6469,8 +6388,6 @@ impl DebruijnIndex { } } -impl Copy for DebruijnIndex {} - impl<'tcx> Repr<'tcx> for AutoAdjustment<'tcx> { fn repr(&self, tcx: &ctxt<'tcx>) -> String { match *self { @@ -6589,14 +6506,13 @@ pub fn make_substs_for_receiver_types<'tcx>(tcx: &ty::ctxt<'tcx>, trait_ref.substs.clone().with_method(meth_tps, meth_regions) } +#[deriving(Copy)] pub enum CopyImplementationError { FieldDoesNotImplementCopy(ast::Name), VariantDoesNotImplementCopy(ast::Name), TypeIsStructural, } -impl Copy for CopyImplementationError {} - pub fn can_type_implement_copy<'tcx>(tcx: &ctxt<'tcx>, self_type: Ty<'tcx>, param_env: &ParameterEnvironment<'tcx>) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 59da0af417cfb..0c014d615caf5 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -47,7 +47,7 @@ pub struct Config { pub uint_type: UintTy, } -#[deriving(Clone, PartialEq)] +#[deriving(Clone, Copy, PartialEq)] pub enum OptLevel { No, // -O0 Less, // -O1 @@ -55,18 +55,14 @@ pub enum OptLevel { Aggressive // -O3 } -impl Copy for OptLevel {} - -#[deriving(Clone, PartialEq)] +#[deriving(Clone, Copy, PartialEq)] pub enum DebugInfoLevel { NoDebugInfo, LimitedDebugInfo, FullDebugInfo, } -impl Copy for DebugInfoLevel {} - -#[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)] +#[deriving(Clone, Copy, PartialEq, PartialOrd, Ord, Eq)] pub enum OutputType { OutputTypeBitcode, OutputTypeAssembly, @@ -75,8 +71,6 @@ pub enum OutputType { OutputTypeExe, } -impl Copy for OutputType {} - #[deriving(Clone)] pub struct Options { // The crate config requested for the session, which may be combined @@ -220,16 +214,14 @@ pub fn basic_options() -> Options { // users can have their own entry // functions that don't start a // scheduler -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum EntryFnType { EntryMain, EntryStart, EntryNone, } -impl Copy for EntryFnType {} - -#[deriving(PartialEq, PartialOrd, Clone, Ord, Eq, Hash)] +#[deriving(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash)] pub enum CrateType { CrateTypeExecutable, CrateTypeDylib, @@ -237,8 +229,6 @@ pub enum CrateType { CrateTypeStaticlib, } -impl Copy for CrateType {} - macro_rules! debugging_opts { ([ $opt:ident ] $cnt:expr ) => ( pub const $opt: u64 = 1 << $cnt; diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 51e18c80d0584..bc6fb1be0758f 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -22,11 +22,9 @@ use syntax::visit::Visitor; // Useful type to use with `Result<>` indicate that an error has already // been reported to the user, so no need to continue checking. -#[deriving(Clone,Show)] +#[deriving(Clone, Copy, Show)] pub struct ErrorReported; -impl Copy for ErrorReported {} - pub fn time(do_it: bool, what: &str, u: U, f: F) -> T where F: FnOnce(U) -> T, { diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index d1816c655fa5f..2b05961bb6a05 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -68,11 +68,9 @@ pub mod DefIdSet { /// /// This uses FNV hashing, as described here: /// http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function -#[deriving(Clone, Default)] +#[deriving(Clone, Copy, Default)] pub struct FnvHasher; -impl Copy for FnvHasher {} - #[allow(missing_copy_implementations)] pub struct FnvState(u64); From 392ea799b8c19e79ed65228841fc47da8660d74a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:06:50 -0500 Subject: [PATCH 10/23] librustc_borrowck: use `#[deriving(Copy)]` --- src/librustc_borrowck/borrowck/mod.rs | 15 +++-------- src/librustc_borrowck/borrowck/move_data.rs | 29 ++++++--------------- src/librustc_borrowck/graphviz.rs | 4 +-- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 7f469db318611..9be87b533f296 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -56,11 +56,9 @@ pub mod gather_loans; pub mod move_data; -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct LoanDataFlowOperator; -impl Copy for LoanDataFlowOperator {} - pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>; impl<'a, 'tcx, 'v> Visitor<'v> for BorrowckCtxt<'a, 'tcx> { @@ -325,14 +323,12 @@ impl<'tcx> LoanPath<'tcx> { // b2b39e8700e37ad32b486b9a8409b50a8a53aa51#commitcomment-7892003 static DOWNCAST_PRINTED_OPERATOR : &'static str = " as "; -#[deriving(PartialEq, Eq, Hash, Show)] +#[deriving(Copy, PartialEq, Eq, Hash, Show)] pub enum LoanPathElem { LpDeref(mc::PointerKind), // `*LV` in doc.rs LpInterior(mc::InteriorKind) // `LV.f` in doc.rs } -impl Copy for LoanPathElem {} - pub fn closure_to_block(closure_id: ast::NodeId, tcx: &ty::ctxt) -> ast::NodeId { match tcx.map.get(closure_id) { @@ -494,21 +490,18 @@ pub struct BckError<'tcx> { code: bckerr_code } +#[deriving(Copy)] pub enum AliasableViolationKind { MutabilityViolation, BorrowViolation(euv::LoanCause) } -impl Copy for AliasableViolationKind {} - -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum MovedValueUseKind { MovedInUse, MovedInCapture, } -impl Copy for MovedValueUseKind {} - /////////////////////////////////////////////////////////////////////////// // Misc diff --git a/src/librustc_borrowck/borrowck/move_data.rs b/src/librustc_borrowck/borrowck/move_data.rs index 00b1377af7304..d033fd808aa40 100644 --- a/src/librustc_borrowck/borrowck/move_data.rs +++ b/src/librustc_borrowck/borrowck/move_data.rs @@ -78,11 +78,9 @@ pub struct FlowedMoveData<'a, 'tcx: 'a> { } /// Index into `MoveData.paths`, used like a pointer -#[deriving(PartialEq, Eq, PartialOrd, Ord, Show)] +#[deriving(Copy, PartialEq, Eq, PartialOrd, Ord, Show)] pub struct MovePathIndex(uint); -impl Copy for MovePathIndex {} - impl MovePathIndex { fn get(&self) -> uint { let MovePathIndex(v) = *self; v @@ -100,11 +98,9 @@ static InvalidMovePathIndex: MovePathIndex = MovePathIndex(uint::MAX); /// Index into `MoveData.moves`, used like a pointer -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub struct MoveIndex(uint); -impl Copy for MoveIndex {} - impl MoveIndex { fn get(&self) -> uint { let MoveIndex(v) = *self; v @@ -134,7 +130,7 @@ pub struct MovePath<'tcx> { pub next_sibling: MovePathIndex, } -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub enum MoveKind { Declared, // When declared, variables start out "moved". MoveExpr, // Expression or binding that moves a variable @@ -142,8 +138,7 @@ pub enum MoveKind { Captured // Closure creation that moves a value } -impl Copy for MoveKind {} - +#[deriving(Copy)] pub struct Move { /// Path being moved. pub path: MovePathIndex, @@ -158,8 +153,7 @@ pub struct Move { pub next_move: MoveIndex } -impl Copy for Move {} - +#[deriving(Copy)] pub struct Assignment { /// Path being assigned. pub path: MovePathIndex, @@ -171,8 +165,7 @@ pub struct Assignment { pub span: Span, } -impl Copy for Assignment {} - +#[deriving(Copy)] pub struct VariantMatch { /// downcast to the variant. pub path: MovePathIndex, @@ -187,20 +180,14 @@ pub struct VariantMatch { pub mode: euv::MatchMode } -impl Copy for VariantMatch {} - -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct MoveDataFlowOperator; -impl Copy for MoveDataFlowOperator {} - pub type MoveDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, MoveDataFlowOperator>; -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct AssignDataFlowOperator; -impl Copy for AssignDataFlowOperator {} - pub type AssignDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, AssignDataFlowOperator>; fn loan_path_is_precise(loan_path: &LoanPath) -> bool { diff --git a/src/librustc_borrowck/graphviz.rs b/src/librustc_borrowck/graphviz.rs index 9d41efd678c7c..3427be1443b3c 100644 --- a/src/librustc_borrowck/graphviz.rs +++ b/src/librustc_borrowck/graphviz.rs @@ -25,15 +25,13 @@ use rustc::middle::dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit}; use rustc::middle::dataflow; use std::rc::Rc; -#[deriving(Show)] +#[deriving(Show, Copy)] pub enum Variant { Loans, Moves, Assigns, } -impl Copy for Variant {} - impl Variant { pub fn short_name(&self) -> &'static str { match *self { From db45be2616edb658427fb4986d2418b22150cb16 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:07:14 -0500 Subject: [PATCH 11/23] librustc_driver: use `#[deriving(Copy)]` --- src/librustc_driver/pretty.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 57004d71c75e4..2eb9d2c67a7cb 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -39,7 +39,7 @@ use std::option; use std::str::FromStr; use arena::TypedArena; -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub enum PpSourceMode { PpmNormal, PpmExpanded, @@ -49,16 +49,12 @@ pub enum PpSourceMode { PpmExpandedHygiene, } -impl Copy for PpSourceMode {} - -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub enum PpMode { PpmSource(PpSourceMode), PpmFlowGraph, } -impl Copy for PpMode {} - pub fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option) { let mut split = name.splitn(1, '='); let first = split.next().unwrap(); From 463475b7fa95cfeddbe9e153b1fdf408965252da Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:09:35 -0500 Subject: [PATCH 12/23] librustc_llvm: use `#[deriving(Copy)]` --- src/librustc_llvm/diagnostic.rs | 6 +-- src/librustc_llvm/lib.rs | 65 ++++++++++----------------------- 2 files changed, 22 insertions(+), 49 deletions(-) diff --git a/src/librustc_llvm/diagnostic.rs b/src/librustc_llvm/diagnostic.rs index 04196feafd22b..3bf9c2d44f721 100644 --- a/src/librustc_llvm/diagnostic.rs +++ b/src/librustc_llvm/diagnostic.rs @@ -17,6 +17,7 @@ use libc::c_char; use {ValueRef, TwineRef, DebugLocRef, DiagnosticInfoRef}; +#[deriving(Copy)] pub enum OptimizationDiagnosticKind { OptimizationRemark, OptimizationMissed, @@ -24,8 +25,6 @@ pub enum OptimizationDiagnosticKind { OptimizationFailure, } -impl Copy for OptimizationDiagnosticKind {} - impl OptimizationDiagnosticKind { pub fn describe(self) -> &'static str { match self { @@ -69,6 +68,7 @@ impl OptimizationDiagnostic { } } +#[deriving(Copy)] pub enum Diagnostic { Optimization(OptimizationDiagnostic), @@ -76,8 +76,6 @@ pub enum Diagnostic { UnknownDiagnostic(DiagnosticInfoRef), } -impl Copy for Diagnostic {} - impl Diagnostic { pub unsafe fn unpack(di: DiagnosticInfoRef) -> Diagnostic { let kind = super::LLVMGetDiagInfoKind(di); diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 8b036b2501578..3528b510ea1bb 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -68,7 +68,7 @@ pub const False: Bool = 0 as Bool; // Consts for the LLVM CallConv type, pre-cast to uint. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum CallConv { CCallConv = 0, FastCallConv = 8, @@ -78,20 +78,18 @@ pub enum CallConv { X86_64_Win64 = 79, } -impl Copy for CallConv {} - +#[deriving(Copy)] pub enum Visibility { LLVMDefaultVisibility = 0, HiddenVisibility = 1, ProtectedVisibility = 2, } -impl Copy for Visibility {} - // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage, // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage. // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either; // they've been removed in upstream LLVM commit r203866. +#[deriving(Copy)] pub enum Linkage { ExternalLinkage = 0, AvailableExternallyLinkage = 1, @@ -106,10 +104,8 @@ pub enum Linkage { CommonLinkage = 14, } -impl Copy for Linkage {} - #[repr(C)] -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum DiagnosticSeverity { Error, Warning, @@ -117,8 +113,6 @@ pub enum DiagnosticSeverity { Note, } -impl Copy for DiagnosticSeverity {} - bitflags! { flags Attribute : u32 { const ZExtAttribute = 1 << 0, @@ -152,6 +146,7 @@ bitflags! { #[repr(u64)] +#[deriving(Copy)] pub enum OtherAttribute { // The following are not really exposed in // the LLVM c api so instead to add these @@ -172,22 +167,18 @@ pub enum OtherAttribute { NonNullAttribute = 1 << 44, } -impl Copy for OtherAttribute {} - +#[deriving(Copy)] pub enum SpecialAttribute { DereferenceableAttribute(u64) } -impl Copy for SpecialAttribute {} - #[repr(C)] +#[deriving(Copy)] pub enum AttributeSet { ReturnIndex = 0, FunctionIndex = !0 } -impl Copy for AttributeSet {} - pub trait AttrHelper { fn apply_llfn(&self, idx: c_uint, llfn: ValueRef); fn apply_callsite(&self, idx: c_uint, callsite: ValueRef); @@ -274,6 +265,7 @@ impl AttrBuilder { } // enum for the LLVM IntPredicate type +#[deriving(Copy)] pub enum IntPredicate { IntEQ = 32, IntNE = 33, @@ -287,9 +279,8 @@ pub enum IntPredicate { IntSLE = 41, } -impl Copy for IntPredicate {} - // enum for the LLVM RealPredicate type +#[deriving(Copy)] pub enum RealPredicate { RealPredicateFalse = 0, RealOEQ = 1, @@ -309,11 +300,9 @@ pub enum RealPredicate { RealPredicateTrue = 15, } -impl Copy for RealPredicate {} - // The LLVM TypeKind type - must stay in sync with the def of // LLVMTypeKind in llvm/include/llvm-c/Core.h -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] #[repr(C)] pub enum TypeKind { Void = 0, @@ -334,9 +323,8 @@ pub enum TypeKind { X86_MMX = 15, } -impl Copy for TypeKind {} - #[repr(C)] +#[deriving(Copy)] pub enum AtomicBinOp { AtomicXchg = 0, AtomicAdd = 1, @@ -351,9 +339,8 @@ pub enum AtomicBinOp { AtomicUMin = 10, } -impl Copy for AtomicBinOp {} - #[repr(C)] +#[deriving(Copy)] pub enum AtomicOrdering { NotAtomic = 0, Unordered = 1, @@ -365,17 +352,15 @@ pub enum AtomicOrdering { SequentiallyConsistent = 7 } -impl Copy for AtomicOrdering {} - // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h) #[repr(C)] +#[deriving(Copy)] pub enum FileType { AssemblyFileType = 0, ObjectFileType = 1 } -impl Copy for FileType {} - +#[deriving(Copy)] pub enum MetadataType { MD_dbg = 0, MD_tbaa = 1, @@ -385,17 +370,14 @@ pub enum MetadataType { MD_tbaa_struct = 5 } -impl Copy for MetadataType {} - // Inline Asm Dialect +#[deriving(Copy)] pub enum AsmDialect { AD_ATT = 0, AD_Intel = 1 } -impl Copy for AsmDialect {} - -#[deriving(PartialEq, Clone)] +#[deriving(Copy, PartialEq, Clone)] #[repr(C)] pub enum CodeGenOptLevel { CodeGenLevelNone = 0, @@ -404,9 +386,7 @@ pub enum CodeGenOptLevel { CodeGenLevelAggressive = 3, } -impl Copy for CodeGenOptLevel {} - -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] #[repr(C)] pub enum RelocMode { RelocDefault = 0, @@ -415,9 +395,8 @@ pub enum RelocMode { RelocDynamicNoPic = 3, } -impl Copy for RelocMode {} - #[repr(C)] +#[deriving(Copy)] pub enum CodeGenModel { CodeModelDefault = 0, CodeModelJITDefault = 1, @@ -427,9 +406,8 @@ pub enum CodeGenModel { CodeModelLarge = 5, } -impl Copy for CodeGenModel {} - #[repr(C)] +#[deriving(Copy)] pub enum DiagnosticKind { DK_InlineAsm = 0, DK_StackSize, @@ -441,8 +419,6 @@ pub enum DiagnosticKind { DK_OptimizationFailure, } -impl Copy for DiagnosticKind {} - // Opaque pointer types #[allow(missing_copy_implementations)] pub enum Module_opaque {} @@ -537,6 +513,7 @@ pub mod debuginfo { pub type DIArray = DIDescriptor; pub type DISubrange = DIDescriptor; + #[deriving(Copy)] pub enum DIDescriptorFlags { FlagPrivate = 1 << 0, FlagProtected = 1 << 1, @@ -555,8 +532,6 @@ pub mod debuginfo { FlagLValueReference = 1 << 14, FlagRValueReference = 1 << 15 } - - impl Copy for DIDescriptorFlags {} } From 5e2bca9e86ee6e40d6aaf6e4f4ba60a6e71b01e4 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:14:38 -0500 Subject: [PATCH 13/23] librustc_trans: use `#[deriving(Copy)]` --- src/librustc_trans/back/write.rs | 4 +--- src/librustc_trans/save/recorder.rs | 3 +-- src/librustc_trans/trans/_match.rs | 16 ++++--------- src/librustc_trans/trans/adt.rs | 4 +--- src/librustc_trans/trans/base.rs | 10 +++----- src/librustc_trans/trans/basic_block.rs | 3 +-- src/librustc_trans/trans/cabi.rs | 8 ++----- src/librustc_trans/trans/cabi_x86_64.rs | 4 +--- src/librustc_trans/trans/callee.rs | 6 ++--- src/librustc_trans/trans/cleanup.rs | 31 +++++++------------------ src/librustc_trans/trans/closure.rs | 3 +-- src/librustc_trans/trans/common.rs | 10 +++----- src/librustc_trans/trans/datum.rs | 12 +++------- src/librustc_trans/trans/debuginfo.rs | 11 +++------ src/librustc_trans/trans/expr.rs | 8 ++----- src/librustc_trans/trans/mod.rs | 3 +-- src/librustc_trans/trans/tvec.rs | 3 +-- src/librustc_trans/trans/type_.rs | 4 +--- src/librustc_trans/trans/type_of.rs | 3 +-- src/librustc_trans/trans/value.rs | 6 ++--- 20 files changed, 43 insertions(+), 109 deletions(-) diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index df7df2f08d983..489d29492c227 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -33,7 +33,7 @@ use std::sync::{Arc, Mutex}; use std::thread; use libc::{c_uint, c_int, c_void}; -#[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)] +#[deriving(Clone, Copy, PartialEq, PartialOrd, Ord, Eq)] pub enum OutputType { OutputTypeBitcode, OutputTypeAssembly, @@ -42,8 +42,6 @@ pub enum OutputType { OutputTypeExe, } -impl Copy for OutputType {} - pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! { unsafe { let cstr = llvm::LLVMRustGetLastError(); diff --git a/src/librustc_trans/save/recorder.rs b/src/librustc_trans/save/recorder.rs index c15ff1d7f0a9d..37d9e5d994073 100644 --- a/src/librustc_trans/save/recorder.rs +++ b/src/librustc_trans/save/recorder.rs @@ -61,6 +61,7 @@ macro_rules! svec { }) } +#[deriving(Copy)] pub enum Row { Variable, Enum, @@ -87,8 +88,6 @@ pub enum Row { FnRef, } -impl Copy for Row {} - impl<'a> FmtStrs<'a> { pub fn new(rec: Box, span: SpanUtils<'a>, krate: String) -> FmtStrs<'a> { FmtStrs { diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index bf17043f0e4ee..1401f1ad1f551 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -228,11 +228,9 @@ use syntax::codemap::Span; use syntax::fold::Folder; use syntax::ptr::P; -#[deriving(Show)] +#[deriving(Copy, Show)] struct ConstantExpr<'a>(&'a ast::Expr); -impl<'a> Copy for ConstantExpr<'a> {} - impl<'a> ConstantExpr<'a> { fn eq(self, other: ConstantExpr<'a>, tcx: &ty::ctxt) -> bool { let ConstantExpr(expr) = self; @@ -301,7 +299,7 @@ impl<'a, 'tcx> Opt<'a, 'tcx> { } } -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum BranchKind { NoBranch, Single, @@ -310,23 +308,19 @@ pub enum BranchKind { CompareSliceLength } -impl Copy for BranchKind {} - pub enum OptResult<'blk, 'tcx: 'blk> { SingleResult(Result<'blk, 'tcx>), RangeResult(Result<'blk, 'tcx>, Result<'blk, 'tcx>), LowerBound(Result<'blk, 'tcx>) } -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub enum TransBindingMode { TrByCopy(/* llbinding */ ValueRef), TrByMove, TrByRef, } -impl Copy for TransBindingMode {} - /// Information about a pattern binding: /// - `llmatch` is a pointer to a stack slot. The stack slot contains a /// pointer into the value being matched. Hence, llmatch has type `T**` @@ -334,7 +328,7 @@ impl Copy for TransBindingMode {} /// - `trmode` is the trans binding mode /// - `id` is the node id of the binding /// - `ty` is the Rust type of the binding -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct BindingInfo<'tcx> { pub llmatch: ValueRef, pub trmode: TransBindingMode, @@ -343,8 +337,6 @@ pub struct BindingInfo<'tcx> { pub ty: Ty<'tcx>, } -impl<'tcx> Copy for BindingInfo<'tcx> {} - type BindingsMap<'tcx> = FnvHashMap>; struct ArmData<'p, 'blk, 'tcx: 'blk> { diff --git a/src/librustc_trans/trans/adt.rs b/src/librustc_trans/trans/adt.rs index 0c2c86fc32dd4..f7edb281b9eda 100644 --- a/src/librustc_trans/trans/adt.rs +++ b/src/librustc_trans/trans/adt.rs @@ -281,14 +281,12 @@ struct Case<'tcx> { } -#[deriving(Eq, PartialEq, Show)] +#[deriving(Copy, Eq, PartialEq, Show)] pub enum PointerField { ThinPointer(uint), FatPointer(uint) } -impl Copy for PointerField {} - impl<'tcx> Case<'tcx> { fn is_zerolen<'a>(&self, cx: &CrateContext<'a, 'tcx>, scapegoat: Ty<'tcx>) -> bool { diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index b947b1746fcab..25fbaa6677684 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -565,10 +565,9 @@ pub fn maybe_name_value(cx: &CrateContext, v: ValueRef, s: &str) { // Used only for creating scalar comparison glue. +#[deriving(Copy)] pub enum scalar_type { nil_type, signed_int, unsigned_int, floating_point, } -impl Copy for scalar_type {} - pub fn compare_scalar_types<'blk, 'tcx>(cx: Block<'blk, 'tcx>, lhs: ValueRef, rhs: ValueRef, @@ -1792,14 +1791,12 @@ pub fn build_return_block<'blk, 'tcx>(fcx: &FunctionContext<'blk, 'tcx>, } } -#[deriving(Clone, Eq, PartialEq)] +#[deriving(Clone, Copy, Eq, PartialEq)] pub enum IsUnboxedClosureFlag { NotUnboxedClosure, IsUnboxedClosure, } -impl Copy for IsUnboxedClosureFlag {} - // trans_closure: Builds an LLVM function out of a source function. // If the function closes over its environment a closure will be // returned. @@ -2194,6 +2191,7 @@ pub fn llvm_linkage_by_name(name: &str) -> Option { /// Enum describing the origin of an LLVM `Value`, for linkage purposes. +#[deriving(Copy)] pub enum ValueOrigin { /// The LLVM `Value` is in this context because the corresponding item was /// assigned to the current compilation unit. @@ -2204,8 +2202,6 @@ pub enum ValueOrigin { InlinedCopy, } -impl Copy for ValueOrigin {} - /// Set the appropriate linkage for an LLVM `ValueRef` (function or global). /// If the `llval` is the direct translation of a specific Rust item, `id` /// should be set to the `NodeId` of that item. (This mapping should be diff --git a/src/librustc_trans/trans/basic_block.rs b/src/librustc_trans/trans/basic_block.rs index dca106a3897fb..476f5e2d618fe 100644 --- a/src/librustc_trans/trans/basic_block.rs +++ b/src/librustc_trans/trans/basic_block.rs @@ -13,10 +13,9 @@ use llvm::{BasicBlockRef}; use trans::value::{Users, Value}; use std::iter::{Filter, Map}; +#[deriving(Copy)] pub struct BasicBlock(pub BasicBlockRef); -impl Copy for BasicBlock {} - pub type Preds = Map< Value, BasicBlock, diff --git a/src/librustc_trans/trans/cabi.rs b/src/librustc_trans/trans/cabi.rs index 7aabd998f7aae..ad2a6db1222c2 100644 --- a/src/librustc_trans/trans/cabi.rs +++ b/src/librustc_trans/trans/cabi.rs @@ -20,7 +20,7 @@ use trans::cabi_arm; use trans::cabi_mips; use trans::type_::Type; -#[deriving(Clone, PartialEq)] +#[deriving(Clone, Copy, PartialEq)] pub enum ArgKind { /// Pass the argument directly using the normal converted /// LLVM type or by coercing to another specified type @@ -31,13 +31,11 @@ pub enum ArgKind { Ignore, } -impl Copy for ArgKind {} - /// Information about how a specific C type /// should be passed to or returned from a function /// /// This is borrowed from clang's ABIInfo.h -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct ArgType { pub kind: ArgKind, /// Original LLVM type @@ -50,8 +48,6 @@ pub struct ArgType { pub attr: option::Option } -impl Copy for ArgType {} - impl ArgType { pub fn direct(ty: Type, cast: option::Option, pad: option::Option, diff --git a/src/librustc_trans/trans/cabi_x86_64.rs b/src/librustc_trans/trans/cabi_x86_64.rs index 4a6bc58051c57..9b678a4f3ae9b 100644 --- a/src/librustc_trans/trans/cabi_x86_64.rs +++ b/src/librustc_trans/trans/cabi_x86_64.rs @@ -24,7 +24,7 @@ use trans::type_::Type; use std::cmp; -#[deriving(Clone, PartialEq)] +#[deriving(Clone, Copy, PartialEq)] enum RegClass { NoClass, Int, @@ -40,8 +40,6 @@ enum RegClass { Memory } -impl Copy for RegClass {} - trait TypeMethods { fn is_reg_ty(&self) -> bool; } diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index f8303a6f03080..3376479b7a42d 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -57,13 +57,12 @@ use syntax::ast; use syntax::ast_map; use syntax::ptr::P; +#[deriving(Copy)] pub struct MethodData { pub llfn: ValueRef, pub llself: ValueRef, } -impl Copy for MethodData {} - pub enum CalleeData<'tcx> { Closure(Datum<'tcx, Lvalue>), @@ -1049,13 +1048,12 @@ pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, bcx } +#[deriving(Copy)] pub enum AutorefArg { DontAutorefArg, DoAutorefArg(ast::NodeId) } -impl Copy for AutorefArg {} - pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, formal_arg_ty: Ty<'tcx>, arg_datum: Datum<'tcx, Expr>, diff --git a/src/librustc_trans/trans/cleanup.rs b/src/librustc_trans/trans/cleanup.rs index e8857de7b73bc..fb2c432ef5cf4 100644 --- a/src/librustc_trans/trans/cleanup.rs +++ b/src/librustc_trans/trans/cleanup.rs @@ -50,13 +50,11 @@ pub struct CleanupScope<'blk, 'tcx: 'blk> { cached_landing_pad: Option, } -#[deriving(Show)] +#[deriving(Copy, Show)] pub struct CustomScopeIndex { index: uint } -impl Copy for CustomScopeIndex {} - pub const EXIT_BREAK: uint = 0; pub const EXIT_LOOP: uint = 1; pub const EXIT_MAX: uint = 2; @@ -83,22 +81,19 @@ impl<'blk, 'tcx: 'blk> fmt::Show for CleanupScopeKind<'blk, 'tcx> { } } -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub enum EarlyExitLabel { UnwindExit, ReturnExit, LoopExit(ast::NodeId, uint) } -impl Copy for EarlyExitLabel {} - +#[deriving(Copy)] pub struct CachedEarlyExit { label: EarlyExitLabel, cleanup_block: BasicBlockRef, } -impl Copy for CachedEarlyExit {} - pub trait Cleanup<'tcx> { fn must_unwind(&self) -> bool; fn clean_on_unwind(&self) -> bool; @@ -111,14 +106,12 @@ pub trait Cleanup<'tcx> { pub type CleanupObj<'tcx> = Box+'tcx>; -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum ScopeId { AstScope(ast::NodeId), CustomScope(CustomScopeIndex) } -impl Copy for ScopeId {} - impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { /// Invoked when we start to trans the code contained within a new cleanup scope. fn push_ast_cleanup_scope(&self, debug_loc: NodeInfo) { @@ -876,6 +869,7 @@ impl EarlyExitLabel { /////////////////////////////////////////////////////////////////////////// // Cleanup types +#[deriving(Copy)] pub struct DropValue<'tcx> { is_immediate: bool, must_unwind: bool, @@ -884,8 +878,6 @@ pub struct DropValue<'tcx> { zero: bool } -impl<'tcx> Copy for DropValue<'tcx> {} - impl<'tcx> Cleanup<'tcx> for DropValue<'tcx> { fn must_unwind(&self) -> bool { self.must_unwind @@ -915,21 +907,18 @@ impl<'tcx> Cleanup<'tcx> for DropValue<'tcx> { } } -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum Heap { HeapExchange } -impl Copy for Heap {} - +#[deriving(Copy)] pub struct FreeValue<'tcx> { ptr: ValueRef, heap: Heap, content_ty: Ty<'tcx> } -impl<'tcx> Copy for FreeValue<'tcx> {} - impl<'tcx> Cleanup<'tcx> for FreeValue<'tcx> { fn must_unwind(&self) -> bool { true @@ -957,6 +946,7 @@ impl<'tcx> Cleanup<'tcx> for FreeValue<'tcx> { } } +#[deriving(Copy)] pub struct FreeSlice { ptr: ValueRef, size: ValueRef, @@ -964,8 +954,6 @@ pub struct FreeSlice { heap: Heap, } -impl Copy for FreeSlice {} - impl<'tcx> Cleanup<'tcx> for FreeSlice { fn must_unwind(&self) -> bool { true @@ -993,12 +981,11 @@ impl<'tcx> Cleanup<'tcx> for FreeSlice { } } +#[deriving(Copy)] pub struct LifetimeEnd { ptr: ValueRef, } -impl Copy for LifetimeEnd {} - impl<'tcx> Cleanup<'tcx> for LifetimeEnd { fn must_unwind(&self) -> bool { false diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index af3daf224e326..d5d954f5a907b 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -102,13 +102,12 @@ use syntax::ast_util; // // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#[deriving(Copy)] pub struct EnvValue<'tcx> { action: ast::CaptureClause, datum: Datum<'tcx, Lvalue> } -impl<'tcx> Copy for EnvValue<'tcx> {} - impl<'tcx> EnvValue<'tcx> { pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String { format!("{}({})", self.action, self.datum.to_string(ccx)) diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index a8e88eca0e19f..4dd4e27c9c0d4 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -119,6 +119,7 @@ pub fn gensym_name(name: &str) -> PathElem { PathName(token::gensym(format!("{}:{}", name, num).as_slice())) } +#[deriving(Copy)] pub struct tydesc_info<'tcx> { pub ty: Ty<'tcx>, pub tydesc: ValueRef, @@ -127,8 +128,6 @@ pub struct tydesc_info<'tcx> { pub name: ValueRef, } -impl<'tcx> Copy for tydesc_info<'tcx> {} - /* * A note on nomenclature of linking: "extern", "foreign", and "upcall". * @@ -155,13 +154,12 @@ impl<'tcx> Copy for tydesc_info<'tcx> {} * */ +#[deriving(Copy)] pub struct NodeInfo { pub id: ast::NodeId, pub span: Span, } -impl Copy for NodeInfo {} - pub fn expr_info(expr: &ast::Expr) -> NodeInfo { NodeInfo { id: expr.id, span: expr.span } } @@ -863,7 +861,7 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, } // Key used to lookup values supplied for type parameters in an expr. -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub enum ExprOrMethodCall { // Type parameters for a path like `None::` ExprId(ast::NodeId), @@ -872,8 +870,6 @@ pub enum ExprOrMethodCall { MethodCall(ty::MethodCall) } -impl Copy for ExprOrMethodCall {} - pub fn node_id_substs<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, node: ExprOrMethodCall) -> subst::Substs<'tcx> { diff --git a/src/librustc_trans/trans/datum.rs b/src/librustc_trans/trans/datum.rs index e32b5792e5da4..75473dc58bf47 100644 --- a/src/librustc_trans/trans/datum.rs +++ b/src/librustc_trans/trans/datum.rs @@ -33,7 +33,7 @@ use syntax::ast; /// describes where the value is stored, what Rust type the value has, /// whether it is addressed by reference, and so forth. Please refer /// the section on datums in `doc.rs` for more details. -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct Datum<'tcx, K> { /// The llvm value. This is either a pointer to the Rust value or /// the value itself, depending on `kind` below. @@ -46,8 +46,6 @@ pub struct Datum<'tcx, K> { pub kind: K, } -impl<'tcx,K:Copy> Copy for Datum<'tcx,K> {} - pub struct DatumBlock<'blk, 'tcx: 'blk, K> { pub bcx: Block<'blk, 'tcx>, pub datum: Datum<'tcx, K>, @@ -65,11 +63,9 @@ pub enum Expr { LvalueExpr, } -#[deriving(Clone, Show)] +#[deriving(Clone, Copy, Show)] pub struct Lvalue; -impl Copy for Lvalue {} - #[deriving(Show)] pub struct Rvalue { pub mode: RvalueMode @@ -86,7 +82,7 @@ impl Drop for Rvalue { fn drop(&mut self) { } } -#[deriving(PartialEq, Eq, Hash, Show)] +#[deriving(Copy, PartialEq, Eq, Hash, Show)] pub enum RvalueMode { /// `val` is a pointer to the actual value (and thus has type *T) ByRef, @@ -95,8 +91,6 @@ pub enum RvalueMode { ByValue, } -impl Copy for RvalueMode {} - pub fn immediate_rvalue<'tcx>(val: ValueRef, ty: Ty<'tcx>) -> Datum<'tcx, Rvalue> { return Datum::new(val, ty, Rvalue::new(ByValue)); } diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 96c39b5796ec4..9a5e6830da194 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -248,11 +248,9 @@ static FLAGS_NONE: c_uint = 0; // Public Interface of debuginfo module //=----------------------------------------------------------------------------- -#[deriving(Show, Hash, Eq, PartialEq, Clone)] +#[deriving(Copy, Show, Hash, Eq, PartialEq, Clone)] struct UniqueTypeId(ast::Name); -impl Copy for UniqueTypeId {} - // The TypeMap is where the CrateDebugContext holds the type metadata nodes // created so far. The metadata nodes are indexed by UniqueTypeId, and, for // faster lookup, also by Ty. The TypeMap is responsible for creating @@ -2320,14 +2318,13 @@ impl<'tcx> VariantMemberDescriptionFactory<'tcx> { } } +#[deriving(Copy)] enum EnumDiscriminantInfo { RegularDiscriminant(DIType), OptimizedDiscriminant(adt::PointerField), NoDiscriminant } -impl Copy for EnumDiscriminantInfo {} - // Returns a tuple of (1) type_metadata_stub of the variant, (2) the llvm_type // of the variant, and (3) a MemberDescriptionFactory for producing the // descriptions of the fields of the variant. This is a rudimentary version of a @@ -3047,14 +3044,12 @@ impl MetadataCreationResult { } } -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] enum DebugLocation { KnownLocation { scope: DIScope, line: uint, col: uint }, UnknownLocation } -impl Copy for DebugLocation {} - impl DebugLocation { fn new(scope: DIScope, line: uint, col: uint) -> DebugLocation { KnownLocation { diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index db44e0ce27197..dd87879b73755 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -73,14 +73,12 @@ use std::rc::Rc; // These are passed around by the code generating functions to track the // destination of a computation's value. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum Dest { SaveIn(ValueRef), Ignore, } -impl Copy for Dest {} - impl Dest { pub fn to_string(&self, ccx: &CrateContext) -> String { match *self { @@ -1889,7 +1887,7 @@ fn float_cast(bcx: Block, } else { llsrc }; } -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub enum cast_kind { cast_pointer, cast_integral, @@ -1898,8 +1896,6 @@ pub enum cast_kind { cast_other, } -impl Copy for cast_kind {} - pub fn cast_type_kind<'tcx>(tcx: &ty::ctxt<'tcx>, t: Ty<'tcx>) -> cast_kind { match t.sty { ty::ty_char => cast_integral, diff --git a/src/librustc_trans/trans/mod.rs b/src/librustc_trans/trans/mod.rs index 9234dfc48bd66..05797d74feefc 100644 --- a/src/librustc_trans/trans/mod.rs +++ b/src/librustc_trans/trans/mod.rs @@ -54,13 +54,12 @@ mod basic_block; mod llrepr; mod cleanup; +#[deriving(Copy)] pub struct ModuleTranslation { pub llcx: ContextRef, pub llmod: ModuleRef, } -impl Copy for ModuleTranslation {} - pub struct CrateTranslation { pub modules: Vec, pub metadata_module: ModuleTranslation, diff --git a/src/librustc_trans/trans/tvec.rs b/src/librustc_trans/trans/tvec.rs index 18ea8055a4eb5..e09032ac2d04f 100644 --- a/src/librustc_trans/trans/tvec.rs +++ b/src/librustc_trans/trans/tvec.rs @@ -89,6 +89,7 @@ pub fn make_drop_glue_unboxed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, }) } +#[deriving(Copy)] pub struct VecTypes<'tcx> { pub unit_ty: Ty<'tcx>, pub llunit_ty: Type, @@ -96,8 +97,6 @@ pub struct VecTypes<'tcx> { pub llunit_alloc_size: u64 } -impl<'tcx> Copy for VecTypes<'tcx> {} - impl<'tcx> VecTypes<'tcx> { pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String { format!("VecTypes {{unit_ty={}, llunit_ty={}, \ diff --git a/src/librustc_trans/trans/type_.rs b/src/librustc_trans/trans/type_.rs index 70b1e99ce8e28..51a0533a7bb63 100644 --- a/src/librustc_trans/trans/type_.rs +++ b/src/librustc_trans/trans/type_.rs @@ -25,14 +25,12 @@ use std::cell::RefCell; use libc::c_uint; -#[deriving(Clone, PartialEq, Show)] +#[deriving(Clone, Copy, PartialEq, Show)] #[repr(C)] pub struct Type { rf: TypeRef } -impl Copy for Type {} - macro_rules! ty { ($e:expr) => ( Type::from_ref(unsafe { $e })) } diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index aa6fd7f0b3941..2801e0ccead6d 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -443,14 +443,13 @@ pub fn align_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) } // Want refinements! (Or case classes, I guess +#[deriving(Copy)] pub enum named_ty { a_struct, an_enum, an_unboxed_closure, } -impl Copy for named_ty {} - pub fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, what: named_ty, did: ast::DefId, diff --git a/src/librustc_trans/trans/value.rs b/src/librustc_trans/trans/value.rs index c7cf86fb1843a..4f9b8c5ea37c9 100644 --- a/src/librustc_trans/trans/value.rs +++ b/src/librustc_trans/trans/value.rs @@ -14,10 +14,9 @@ use trans::basic_block::BasicBlock; use trans::common::Block; use libc::c_uint; +#[deriving(Copy)] pub struct Value(pub ValueRef); -impl Copy for Value {} - macro_rules! opt_val { ($e:expr) => ( unsafe { match $e { @@ -126,10 +125,9 @@ impl Value { } /// Wrapper for LLVM UseRef +#[deriving(Copy)] pub struct Use(UseRef); -impl Copy for Use {} - impl Use { pub fn get(&self) -> UseRef { let Use(v) = *self; v From fa0383f38d4b165ad2285efade1bbdbb780cdfe5 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:16:06 -0500 Subject: [PATCH 14/23] librustc_typeck: use `#[deriving(Copy)]` --- src/librustc_typeck/check/method/mod.rs | 4 +--- src/librustc_typeck/check/mod.rs | 11 +++-------- src/librustc_typeck/check/writeback.rs | 3 +-- src/librustc_typeck/collect.rs | 3 +-- src/librustc_typeck/rscope.rs | 3 +-- src/librustc_typeck/variance.rs | 14 ++++---------- 6 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index ffaeceb3eed11..3b7eb22e56cc4 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -46,14 +46,12 @@ pub enum MethodError { // A pared down enum describing just the places from which a method // candidate can arise. Used for error reporting only. -#[deriving(PartialOrd, Ord, PartialEq, Eq)] +#[deriving(Copy, PartialOrd, Ord, PartialEq, Eq)] pub enum CandidateSource { ImplSource(ast::DefId), TraitSource(/* trait id */ ast::DefId), } -impl Copy for CandidateSource {} - type MethodIndex = uint; // just for doc purposes /// Determines whether the type `self_ty` supports a method name `method_name` or not. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 9e249cc449d07..bbc33826f3551 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -166,6 +166,7 @@ pub struct Inherited<'a, 'tcx: 'a> { /// When type-checking an expression, we propagate downward /// whatever type hint we are able in the form of an `Expectation`. +#[deriving(Copy)] enum Expectation<'tcx> { /// We know nothing about what type this expression should have. NoExpectation, @@ -177,8 +178,6 @@ enum Expectation<'tcx> { ExpectCastableToType(Ty<'tcx>), } -impl<'tcx> Copy for Expectation<'tcx> {} - impl<'tcx> Expectation<'tcx> { // Disregard "castable to" expectations because they // can lead us astray. Consider for example `if cond @@ -1976,14 +1975,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum LvaluePreference { PreferMutLvalue, NoPreference } -impl Copy for LvaluePreference {} - /// Executes an autoderef loop for the type `t`. At each step, invokes `should_stop` to decide /// whether to terminate the loop. Returns the final type and number of derefs that it performed. /// @@ -2856,14 +2853,12 @@ pub fn lookup_tup_field_ty<'tcx>(tcx: &ty::ctxt<'tcx>, // Controls whether the arguments are automatically referenced. This is useful // for overloaded binary and unary operators. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum AutorefArgs { Yes, No, } -impl Copy for AutorefArgs {} - /// Controls whether the arguments are tupled. This is used for the call /// operator. /// diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index b73381966e8dc..700d12116060c 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -343,6 +343,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { /////////////////////////////////////////////////////////////////////////// // Resolution reason. +#[deriving(Copy)] enum ResolveReason { ResolvingExpr(Span), ResolvingLocal(Span), @@ -351,8 +352,6 @@ enum ResolveReason { ResolvingUnboxedClosure(ast::DefId), } -impl Copy for ResolveReason {} - impl ResolveReason { fn span(&self, tcx: &ty::ctxt) -> Span { match *self { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 280b42f0959d2..4612acb04b2f0 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -490,6 +490,7 @@ fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } } +#[deriving(Copy)] enum ConvertMethodContext<'a> { /// Used when converting implementation methods. ImplConvertMethodContext, @@ -498,8 +499,6 @@ enum ConvertMethodContext<'a> { TraitConvertMethodContext(ast::DefId, &'a [ast::TraitItem]), } -impl<'a> Copy for ConvertMethodContext<'a> {} - fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>, convert_method_context: ConvertMethodContext, container: ImplOrTraitItemContainer, diff --git a/src/librustc_typeck/rscope.rs b/src/librustc_typeck/rscope.rs index 39c7a87837ca1..f43e8579022e9 100644 --- a/src/librustc_typeck/rscope.rs +++ b/src/librustc_typeck/rscope.rs @@ -36,10 +36,9 @@ pub trait RegionScope { // A scope in which all regions must be explicitly named. This is used // for types that appear in structs and so on. +#[deriving(Copy)] pub struct ExplicitRscope; -impl Copy for ExplicitRscope {} - impl RegionScope for ExplicitRscope { fn default_region_bound(&self, _span: Span) -> Option { None diff --git a/src/librustc_typeck/variance.rs b/src/librustc_typeck/variance.rs index 67478e0bfa77e..ef0d1bc3859fa 100644 --- a/src/librustc_typeck/variance.rs +++ b/src/librustc_typeck/variance.rs @@ -229,19 +229,16 @@ pub fn infer_variance(tcx: &ty::ctxt) { type VarianceTermPtr<'a> = &'a VarianceTerm<'a>; -#[deriving(Show)] +#[deriving(Copy, Show)] struct InferredIndex(uint); -impl Copy for InferredIndex {} - +#[deriving(Copy)] enum VarianceTerm<'a> { ConstantTerm(ty::Variance), TransformTerm(VarianceTermPtr<'a>, VarianceTermPtr<'a>), InferredTerm(InferredIndex), } -impl<'a> Copy for VarianceTerm<'a> {} - impl<'a> fmt::Show for VarianceTerm<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { @@ -268,14 +265,12 @@ struct TermsContext<'a, 'tcx: 'a> { inferred_infos: Vec> , } -#[deriving(Show, PartialEq)] +#[deriving(Copy, Show, PartialEq)] enum ParamKind { TypeParam, RegionParam } -impl Copy for ParamKind {} - struct InferredInfo<'a> { item_id: ast::NodeId, kind: ParamKind, @@ -427,13 +422,12 @@ struct ConstraintContext<'a, 'tcx: 'a> { /// Declares that the variable `decl_id` appears in a location with /// variance `variance`. +#[deriving(Copy)] struct Constraint<'a> { inferred: InferredIndex, variance: &'a VarianceTerm<'a>, } -impl<'a> Copy for Constraint<'a> {} - fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>, krate: &ast::Crate) -> ConstraintContext<'a, 'tcx> { From 4c007568bfb27fc4ac6cc2dd485099836c6af702 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:17:42 -0500 Subject: [PATCH 15/23] librustdoc: use `#[deriving(Copy)]` --- src/librustdoc/clean/mod.rs | 12 +++--------- src/librustdoc/doctree.rs | 4 +--- src/librustdoc/html/format.rs | 9 ++++----- src/librustdoc/html/item_type.rs | 4 +--- src/librustdoc/html/render.rs | 3 +-- src/librustdoc/stability_summary.rs | 3 +-- 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 661d6ec241ade..ed92320279591 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1188,7 +1188,7 @@ pub enum Type { PolyTraitRef(Vec), } -#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash)] +#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Eq, Hash)] pub enum PrimitiveType { Int, I8, I16, I32, I64, Uint, U8, U16, U32, U64, @@ -1200,9 +1200,7 @@ pub enum PrimitiveType { PrimitiveTuple, } -impl Copy for PrimitiveType {} - -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, Copy, Encodable, Decodable)] pub enum TypeKind { TypeEnum, TypeFunction, @@ -1215,8 +1213,6 @@ pub enum TypeKind { TypeTypedef, } -impl Copy for TypeKind {} - impl PrimitiveType { fn from_str(s: &str) -> Option { match s.as_slice() { @@ -1873,14 +1869,12 @@ impl Clean for doctree::Constant { } } -#[deriving(Show, Clone, Encodable, Decodable, PartialEq)] +#[deriving(Copy, Show, Clone, Encodable, Decodable, PartialEq)] pub enum Mutability { Mutable, Immutable, } -impl Copy for Mutability {} - impl Clean for ast::Mutability { fn clean(&self, _: &DocContext) -> Mutability { match self { diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 6592ca498dc64..83552884d7ffa 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -70,7 +70,7 @@ impl Module { } } -#[deriving(Show, Clone, Encodable, Decodable)] +#[deriving(Copy, Show, Clone, Encodable, Decodable)] pub enum StructType { /// A normal struct Plain, @@ -82,8 +82,6 @@ pub enum StructType { Unit } -impl Copy for StructType {} - pub enum TypeBound { RegionBound, TraitBound(ast::TraitRef) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 1e243906b2341..5572bcb6aa8f0 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -29,15 +29,19 @@ use html::render::{cache, CURRENT_LOCATION_KEY}; /// Helper to render an optional visibility with a space after it (if the /// visibility is preset) +#[deriving(Copy)] pub struct VisSpace(pub Option); /// Similarly to VisSpace, this structure is used to render a function style with a /// space after it. +#[deriving(Copy)] pub struct UnsafetySpace(pub ast::Unsafety); /// Wrapper struct for properly emitting a method declaration. pub struct Method<'a>(pub &'a clean::SelfTy, pub &'a clean::FnDecl); /// Similar to VisSpace, but used for mutability +#[deriving(Copy)] pub struct MutableSpace(pub clean::Mutability); /// Similar to VisSpace, but used for mutability +#[deriving(Copy)] pub struct RawMutableSpace(pub clean::Mutability); /// Wrapper struct for properly emitting the stability level. pub struct Stability<'a>(pub &'a Option); @@ -48,11 +52,6 @@ pub struct WhereClause<'a>(pub &'a clean::Generics); /// Wrapper struct for emitting type parameter bounds. pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]); -impl Copy for VisSpace {} -impl Copy for UnsafetySpace {} -impl Copy for MutableSpace {} -impl Copy for RawMutableSpace {} - impl VisSpace { pub fn get(&self) -> Option { let VisSpace(v) = *self; v diff --git a/src/librustdoc/html/item_type.rs b/src/librustdoc/html/item_type.rs index 580b7fbe1a3da..7c346539f6a79 100644 --- a/src/librustdoc/html/item_type.rs +++ b/src/librustdoc/html/item_type.rs @@ -19,7 +19,7 @@ use clean; /// discriminants. JavaScript then is used to decode them into the original value. /// Consequently, every change to this type should be synchronized to /// the `itemTypes` mapping table in `static/main.js`. -#[deriving(PartialEq, Clone)] +#[deriving(Copy, PartialEq, Clone)] pub enum ItemType { Module = 0, Struct = 1, @@ -41,8 +41,6 @@ pub enum ItemType { Constant = 18, } -impl Copy for ItemType {} - impl ItemType { pub fn from_item(item: &clean::Item) -> ItemType { match item.inner { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 3e6cffa1304ce..8831b5e7d96fe 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -225,13 +225,12 @@ struct Source<'a>(&'a str); // Helper structs for rendering items/sidebars and carrying along contextual // information +#[deriving(Copy)] struct Item<'a> { cx: &'a Context, item: &'a clean::Item, } -impl<'a> Copy for Item<'a> {} - struct Sidebar<'a> { cx: &'a Context, item: &'a clean::Item, } /// Struct representing one entry in the JS search index. These are all emitted diff --git a/src/librustdoc/stability_summary.rs b/src/librustdoc/stability_summary.rs index 4fbd249660f9f..2f3079f75b923 100644 --- a/src/librustdoc/stability_summary.rs +++ b/src/librustdoc/stability_summary.rs @@ -27,6 +27,7 @@ use html::render::cache; #[deriving(Zero, Encodable, Decodable, PartialEq, Eq)] /// The counts for each stability level. +#[deriving(Copy)] pub struct Counts { pub deprecated: uint, pub experimental: uint, @@ -39,8 +40,6 @@ pub struct Counts { pub unmarked: uint, } -impl Copy for Counts {} - impl Add for Counts { fn add(self, other: Counts) -> Counts { Counts { From 1d25271e054fdefe5e940ab4cc5e098f47c46966 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:19:48 -0500 Subject: [PATCH 16/23] librustrt: use `#[deriving(Copy)]` --- src/libstd/rt/unwind.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 5d5440b887d89..4d5feaa2454b7 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -397,6 +397,7 @@ pub mod eabi { pub struct DISPATCHER_CONTEXT; #[repr(C)] + #[deriving(Copy)] pub enum EXCEPTION_DISPOSITION { ExceptionContinueExecution, ExceptionContinueSearch, @@ -404,8 +405,6 @@ pub mod eabi { ExceptionCollidedUnwind } - impl Copy for EXCEPTION_DISPOSITION {} - type _Unwind_Personality_Fn = extern "C" fn( version: c_int, From 2df30a47e2e0ef563d9ed80cb3cc258cbea0f53a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:20:43 -0500 Subject: [PATCH 17/23] libserialize: use `#[deriving(Copy)]` --- src/libserialize/base64.rs | 12 ++++-------- src/libserialize/hex.rs | 3 +-- src/libserialize/json.rs | 8 ++------ 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index 8ded963b9284a..f1dffa55bb01a 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -19,6 +19,7 @@ use std::fmt; use std::error; /// Available encoding character sets +#[deriving(Copy)] pub enum CharacterSet { /// The standard character set (uses `+` and `/`) Standard, @@ -26,9 +27,8 @@ pub enum CharacterSet { UrlSafe } -impl Copy for CharacterSet {} - /// Available newline types +#[deriving(Copy)] pub enum Newline { /// A linefeed (i.e. Unix-style newline) LF, @@ -36,9 +36,8 @@ pub enum Newline { CRLF } -impl Copy for Newline {} - /// Contains configuration parameters for `to_base64`. +#[deriving(Copy)] pub struct Config { /// Character set to use pub char_set: CharacterSet, @@ -50,8 +49,6 @@ pub struct Config { pub line_length: Option } -impl Copy for Config {} - /// Configuration for RFC 4648 standard base64 encoding pub static STANDARD: Config = Config {char_set: Standard, newline: Newline::CRLF, pad: true, line_length: None}; @@ -180,6 +177,7 @@ pub trait FromBase64 for Sized? { } /// Errors that can occur when decoding a base64 encoded string +#[deriving(Copy)] pub enum FromBase64Error { /// The input contained a character not part of the base64 format InvalidBase64Byte(u8, uint), @@ -187,8 +185,6 @@ pub enum FromBase64Error { InvalidBase64Length, } -impl Copy for FromBase64Error {} - impl fmt::Show for FromBase64Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 22392056ddf21..977a31c240bd3 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -61,6 +61,7 @@ pub trait FromHex for Sized? { } /// Errors that can occur when decoding a hex encoded string +#[deriving(Copy)] pub enum FromHexError { /// The input contained a character not part of the hex format InvalidHexCharacter(char, uint), @@ -68,8 +69,6 @@ pub enum FromHexError { InvalidHexLength, } -impl Copy for FromHexError {} - impl fmt::Show for FromHexError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 6d143329b0c30..d3d1aa1d78879 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -226,7 +226,7 @@ pub type Array = Vec; pub type Object = BTreeMap; /// The errors that can arise while parsing a JSON stream. -#[deriving(Clone, PartialEq)] +#[deriving(Clone, Copy, PartialEq)] pub enum ErrorCode { InvalidSyntax, InvalidNumber, @@ -247,17 +247,13 @@ pub enum ErrorCode { NotUtf8, } -impl Copy for ErrorCode {} - -#[deriving(Clone, PartialEq, Show)] +#[deriving(Clone, Copy, PartialEq, Show)] pub enum ParserError { /// msg, line, col SyntaxError(ErrorCode, uint, uint), IoError(io::IoErrorKind, &'static str), } -impl Copy for ParserError {} - // Builder and Parser have the same errors. pub type BuilderError = ParserError; From a77e8a63d5d4c0fa04a878995824e727870135f9 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:24:36 -0500 Subject: [PATCH 18/23] libstd: use `#[deriving(Copy)]` --- src/libstd/ascii.rs | 5 +---- src/libstd/comm/mod.rs | 4 +--- src/libstd/dynamic_lib.rs | 4 +--- src/libstd/io/mod.rs | 26 +++++++------------------- src/libstd/io/net/addrinfo.rs | 16 +++++----------- src/libstd/io/net/ip.rs | 9 ++------- src/libstd/io/process.rs | 8 ++------ src/libstd/io/util.rs | 9 +++------ src/libstd/num/strconv.rs | 10 +++------- src/libstd/os.rs | 6 ++---- src/libstd/path/windows.rs | 5 +---- src/libstd/rand/mod.rs | 4 +--- src/libstd/time/duration.rs | 5 +---- 13 files changed, 30 insertions(+), 81 deletions(-) diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index c436de0d193b8..2c4dc5313bbfa 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -18,7 +18,6 @@ use core::kinds::Sized; use fmt; use iter::IteratorExt; -use kinds::Copy; use mem; use ops::FnMut; use option::Option; @@ -29,11 +28,9 @@ use string::{String, IntoString}; use vec::Vec; /// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero. -#[deriving(Clone, PartialEq, PartialOrd, Ord, Eq, Hash)] +#[deriving(Clone, Copy, PartialEq, PartialOrd, Ord, Eq, Hash)] pub struct Ascii { chr: u8 } -impl Copy for Ascii {} - impl Ascii { /// Converts an ascii character into a `u8`. #[inline] diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs index 8f945fec4d562..9043cb8c7d6f5 100644 --- a/src/libstd/comm/mod.rs +++ b/src/libstd/comm/mod.rs @@ -391,7 +391,7 @@ pub struct SyncSender { /// This enumeration is the list of the possible reasons that try_recv could not /// return data when called. -#[deriving(PartialEq, Clone, Show)] +#[deriving(PartialEq, Clone, Copy, Show)] #[experimental = "this is likely to be removed in changing try_recv()"] pub enum TryRecvError { /// This channel is currently empty, but the sender(s) have not yet @@ -402,8 +402,6 @@ pub enum TryRecvError { Disconnected, } -impl Copy for TryRecvError {} - /// This enumeration is the list of the possible error outcomes for the /// `SyncSender::try_send` method. #[deriving(PartialEq, Clone, Show)] diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 758dab1a10726..291f384d619d9 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -215,7 +215,6 @@ pub mod dl { use c_str::{CString, ToCStr}; use libc; - use kinds::Copy; use ops::FnOnce; use ptr; use result::*; @@ -265,6 +264,7 @@ pub mod dl { dlclose(handle as *mut libc::c_void); () } + #[deriving(Copy)] pub enum Rtld { Lazy = 1, Now = 2, @@ -272,8 +272,6 @@ pub mod dl { Local = 0, } - impl Copy for Rtld {} - #[link_name = "dl"] extern { fn dlopen(filename: *const libc::c_char, diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 5807a3bc4662e..dbf61b132e08b 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -232,7 +232,6 @@ use error::{FromError, Error}; use fmt; use int; use iter::{Iterator, IteratorExt}; -use kinds::Copy; use mem::transmute; use ops::{BitOr, BitXor, BitAnd, Sub, Not, FnOnce}; use option::Option; @@ -367,7 +366,7 @@ impl FromError for Box { } /// A list specifying general categories of I/O error. -#[deriving(PartialEq, Eq, Clone, Show)] +#[deriving(Copy, PartialEq, Eq, Clone, Show)] pub enum IoErrorKind { /// Any I/O error not part of this list. OtherIoError, @@ -422,8 +421,6 @@ pub enum IoErrorKind { NoProgress, } -impl Copy for IoErrorKind {} - /// A trait that lets you add a `detail` to an IoError easily trait UpdateIoError { /// Returns an IoError with updated description and detail @@ -1561,6 +1558,7 @@ impl BufferPrelude for T { /// When seeking, the resulting cursor is offset from a base by the offset given /// to the `seek` function. The base used is specified by this enumeration. +#[deriving(Copy)] pub enum SeekStyle { /// Seek from the beginning of the stream SeekSet, @@ -1570,8 +1568,6 @@ pub enum SeekStyle { SeekCur, } -impl Copy for SeekStyle {} - /// An object implementing `Seek` internally has some form of cursor which can /// be moved within a stream of bytes. The stream typically has a fixed size, /// allowing seeking relative to either end. @@ -1685,6 +1681,7 @@ pub fn standard_error(kind: IoErrorKind) -> IoError { /// A mode specifies how a file should be opened or created. These modes are /// passed to `File::open_mode` and are used to control where the file is /// positioned when it is initially opened. +#[deriving(Copy)] pub enum FileMode { /// Opens a file positioned at the beginning. Open, @@ -1694,10 +1691,9 @@ pub enum FileMode { Truncate, } -impl Copy for FileMode {} - /// Access permissions with which the file should be opened. `File`s /// opened with `Read` will return an error if written to. +#[deriving(Copy)] pub enum FileAccess { /// Read-only access, requests to write will result in an error Read, @@ -1707,10 +1703,8 @@ pub enum FileAccess { ReadWrite, } -impl Copy for FileAccess {} - /// Different kinds of files which can be identified by a call to stat -#[deriving(PartialEq, Show, Hash, Clone)] +#[deriving(Copy, PartialEq, Show, Hash, Clone)] pub enum FileType { /// This is a normal file, corresponding to `S_IFREG` RegularFile, @@ -1731,8 +1725,6 @@ pub enum FileType { Unknown, } -impl Copy for FileType {} - /// A structure used to describe metadata information about a file. This /// structure is created through the `stat` method on a `Path`. /// @@ -1750,7 +1742,7 @@ impl Copy for FileType {} /// println!("byte size: {}", info.size); /// # } /// ``` -#[deriving(Hash)] +#[deriving(Copy, Hash)] pub struct FileStat { /// The size of the file, in bytes pub size: u64, @@ -1784,14 +1776,12 @@ pub struct FileStat { pub unstable: UnstableFileStat, } -impl Copy for FileStat {} - /// This structure represents all of the possible information which can be /// returned from a `stat` syscall which is not contained in the `FileStat` /// structure. This information is not necessarily platform independent, and may /// have different meanings or no meaning at all on some platforms. #[unstable] -#[deriving(Hash)] +#[deriving(Copy, Hash)] pub struct UnstableFileStat { /// The ID of the device containing the file. pub device: u64, @@ -1815,8 +1805,6 @@ pub struct UnstableFileStat { pub gen: u64, } -impl Copy for UnstableFileStat {} - bitflags! { #[doc = "A set of permissions for a file or directory is represented"] #[doc = "by a set of flags which are or'd together."] diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index fc81ab7b57a3e..69ba64d856e7f 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -22,23 +22,22 @@ pub use self::Protocol::*; use iter::IteratorExt; use io::{IoResult}; use io::net::ip::{SocketAddr, IpAddr}; -use kinds::Copy; use option::Option; use option::Option::{Some, None}; use sys; use vec::Vec; /// Hints to the types of sockets that are desired when looking up hosts +#[deriving(Copy)] pub enum SocketType { Stream, Datagram, Raw } -impl Copy for SocketType {} - /// Flags which can be or'd into the `flags` field of a `Hint`. These are used /// to manipulate how a query is performed. /// /// The meaning of each of these flags can be found with `man -s 3 getaddrinfo` +#[deriving(Copy)] pub enum Flag { AddrConfig, All, @@ -49,21 +48,19 @@ pub enum Flag { V4Mapped, } -impl Copy for Flag {} - /// A transport protocol associated with either a hint or a return value of /// `lookup` +#[deriving(Copy)] pub enum Protocol { TCP, UDP } -impl Copy for Protocol {} - /// This structure is used to provide hints when fetching addresses for a /// remote host to control how the lookup is performed. /// /// For details on these fields, see their corresponding definitions via /// `man -s 3 getaddrinfo` +#[deriving(Copy)] pub struct Hint { pub family: uint, pub socktype: Option, @@ -71,8 +68,7 @@ pub struct Hint { pub flags: uint, } -impl Copy for Hint {} - +#[deriving(Copy)] pub struct Info { pub address: SocketAddr, pub family: uint, @@ -81,8 +77,6 @@ pub struct Info { pub flags: uint, } -impl Copy for Info {} - /// Easy name resolution. Given a hostname, returns the list of IP addresses for /// that hostname. pub fn get_host_addresses(host: &str) -> IoResult> { diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 5a3f5bd466884..71776b6c46af7 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -18,7 +18,6 @@ pub use self::IpAddr::*; use fmt; -use kinds::Copy; use io::{mod, IoResult, IoError}; use io::net; use iter::{Iterator, IteratorExt}; @@ -32,14 +31,12 @@ use vec::Vec; pub type Port = u16; -#[deriving(PartialEq, Eq, Clone, Hash)] +#[deriving(Copy, PartialEq, Eq, Clone, Hash)] pub enum IpAddr { Ipv4Addr(u8, u8, u8, u8), Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16) } -impl Copy for IpAddr {} - impl fmt::Show for IpAddr { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { @@ -65,14 +62,12 @@ impl fmt::Show for IpAddr { } } -#[deriving(PartialEq, Eq, Clone, Hash)] +#[deriving(Copy, PartialEq, Eq, Clone, Hash)] pub struct SocketAddr { pub ip: IpAddr, pub port: Port, } -impl Copy for SocketAddr {} - impl fmt::Show for SocketAddr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.ip { diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 60360a2bc6445..9da1117f2272a 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -461,7 +461,7 @@ pub struct ProcessOutput { } /// Describes what to do with a standard io stream for a child process. -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub enum StdioContainer { /// This stream will be ignored. This is the equivalent of attaching the /// stream to `/dev/null` @@ -481,11 +481,9 @@ pub enum StdioContainer { CreatePipe(bool /* readable */, bool /* writable */), } -impl Copy for StdioContainer {} - /// Describes the result of a process after it has terminated. /// Note that Windows have no signals, so the result is usually ExitStatus. -#[deriving(PartialEq, Eq, Clone)] +#[deriving(PartialEq, Eq, Clone, Copy)] pub enum ProcessExit { /// Normal termination with an exit status. ExitStatus(int), @@ -494,8 +492,6 @@ pub enum ProcessExit { ExitSignal(int), } -impl Copy for ProcessExit {} - impl fmt::Show for ProcessExit { /// Format a ProcessExit enum, to nicely present the information. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index faa52226a03b7..18fabcbd1a2a4 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -81,20 +81,18 @@ impl Buffer for LimitReader { } /// A `Writer` which ignores bytes written to it, like /dev/null. +#[deriving(Copy)] pub struct NullWriter; -impl Copy for NullWriter {} - impl Writer for NullWriter { #[inline] fn write(&mut self, _buf: &[u8]) -> io::IoResult<()> { Ok(()) } } /// A `Reader` which returns an infinite stream of 0 bytes, like /dev/zero. +#[deriving(Copy)] pub struct ZeroReader; -impl Copy for ZeroReader {} - impl Reader for ZeroReader { #[inline] fn read(&mut self, buf: &mut [u8]) -> io::IoResult { @@ -113,10 +111,9 @@ impl Buffer for ZeroReader { } /// A `Reader` which is always at EOF, like /dev/null. +#[deriving(Copy)] pub struct NullReader; -impl Copy for NullReader {} - impl Reader for NullReader { #[inline] fn read(&mut self, _buf: &mut [u8]) -> io::IoResult { diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 2b319640d1b4e..016c4bd532a17 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -17,7 +17,6 @@ pub use self::SignificantDigits::*; pub use self::SignFormat::*; use char::{mod, Char}; -use kinds::Copy; use num::{mod, Int, Float, FPNaN, FPInfinite, ToPrimitive}; use ops::FnMut; use slice::{SliceExt, CloneSliceExt}; @@ -26,6 +25,7 @@ use string::String; use vec::Vec; /// A flag that specifies whether to use exponential (scientific) notation. +#[deriving(Copy)] pub enum ExponentFormat { /// Do not use exponential notation. ExpNone, @@ -38,10 +38,9 @@ pub enum ExponentFormat { ExpBin, } -impl Copy for ExponentFormat {} - /// The number of digits used for emitting the fractional part of a number, if /// any. +#[deriving(Copy)] pub enum SignificantDigits { /// All calculable digits will be printed. /// @@ -57,9 +56,8 @@ pub enum SignificantDigits { DigExact(uint) } -impl Copy for SignificantDigits {} - /// How to emit the sign of a number. +#[deriving(Copy)] pub enum SignFormat { /// No sign will be printed. The exponent sign will also be emitted. SignNone, @@ -71,8 +69,6 @@ pub enum SignFormat { SignAll, } -impl Copy for SignFormat {} - /// Converts an integral number to its string representation as a byte vector. /// This is meant to be a common base implementation for all integral string /// conversion functions like `to_string()` or `to_str_radix()`. diff --git a/src/libstd/os.rs b/src/libstd/os.rs index a049ea01b6d49..dcc73f7844a49 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -361,6 +361,7 @@ pub fn join_paths(paths: &[T]) -> Result, &'static st } /// A low-level OS in-memory pipe. +#[deriving(Copy)] pub struct Pipe { /// A file descriptor representing the reading end of the pipe. Data written /// on the `out` file descriptor can be read from this file descriptor. @@ -370,8 +371,6 @@ pub struct Pipe { pub writer: c_int, } -impl Copy for Pipe {} - /// Creates a new low-level OS in-memory pipe. /// /// This function can fail to succeed if there are no more resources available @@ -861,6 +860,7 @@ pub enum MapOption { impl Copy for MapOption {} /// Possible errors when creating a map. +#[deriving(Copy)] pub enum MapError { /// # The following are POSIX-specific /// @@ -905,8 +905,6 @@ pub enum MapError { ErrMapViewOfFile(uint) } -impl Copy for MapError {} - impl fmt::Show for MapError { fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result { let str = match *self { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 5cbefb0d3d8e0..b498b3e8ad083 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -22,7 +22,6 @@ use hash; use io::Writer; use iter::{AdditiveIterator, DoubleEndedIteratorExt, Extend}; use iter::{Iterator, IteratorExt, Map}; -use kinds::Copy; use mem; use option::Option; use option::Option::{Some, None}; @@ -970,7 +969,7 @@ pub fn is_sep_byte_verbatim(u: &u8) -> bool { } /// Prefix types for Path -#[deriving(PartialEq, Clone, Show)] +#[deriving(Copy, PartialEq, Clone, Show)] pub enum PathPrefix { /// Prefix `\\?\`, uint is the length of the following component VerbatimPrefix(uint), @@ -986,8 +985,6 @@ pub enum PathPrefix { DiskPrefix } -impl Copy for PathPrefix {} - fn parse_prefix<'a>(mut path: &'a str) -> Option { if path.starts_with("\\\\") { // \\ diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index d8e1fc2565469..0035e5747aa69 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -225,7 +225,6 @@ use cell::RefCell; use clone::Clone; use io::IoResult; use iter::{Iterator, IteratorExt}; -use kinds::Copy; use mem; use rc::Rc; use result::Result::{Ok, Err}; @@ -246,12 +245,11 @@ pub mod reader; /// The standard RNG. This is designed to be efficient on the current /// platform. +#[deriving(Copy)] pub struct StdRng { rng: IsaacWordRng, } -impl Copy for StdRng {} - impl StdRng { /// Create a randomly seeded instance of `StdRng`. /// diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 85ed27853c454..7cb14e8e4bc62 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -13,7 +13,6 @@ #![experimental] use {fmt, i64}; -use kinds::Copy; use ops::{Add, Sub, Mul, Div, Neg, FnOnce}; use option::Option; use option::Option::{Some, None}; @@ -47,7 +46,7 @@ macro_rules! try_opt { /// ISO 8601 time duration with nanosecond precision. /// This also allows for the negative duration; see individual methods for details. -#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] +#[deriving(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct Duration { secs: i64, nanos: i32, // Always 0 <= nanos < NANOS_PER_SEC @@ -65,8 +64,6 @@ pub const MAX: Duration = Duration { nanos: (i64::MAX % MILLIS_PER_SEC) as i32 * NANOS_PER_MILLI }; -impl Copy for Duration {} - impl Duration { /// Makes a new `Duration` with given number of weeks. /// Equivalent to `Duration::seconds(weeks * 7 * 24 * 60 * 60), with overflow checks. From 86f8c127dd806940fe201b510b9284750fb17271 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:32:24 -0500 Subject: [PATCH 19/23] libsyntax: use `#[deriving(Copy)]` --- src/libsyntax/abi.rs | 19 ++-- src/libsyntax/ast.rs | 120 +++++++------------------- src/libsyntax/ast_map/blocks.rs | 6 +- src/libsyntax/ast_map/mod.rs | 12 +-- src/libsyntax/ast_util.rs | 4 +- src/libsyntax/attr.rs | 16 +--- src/libsyntax/codemap.rs | 27 ++---- src/libsyntax/diagnostic.rs | 18 ++-- src/libsyntax/ext/base.rs | 3 +- src/libsyntax/ext/deriving/cmp/ord.rs | 3 +- src/libsyntax/ext/mtwt.rs | 4 +- src/libsyntax/feature_gate.rs | 3 +- src/libsyntax/parse/lexer/comments.rs | 4 +- src/libsyntax/parse/obsolete.rs | 4 +- src/libsyntax/parse/parser.rs | 4 +- src/libsyntax/parse/token.rs | 19 ++-- src/libsyntax/print/pp.rs | 18 ++-- src/libsyntax/print/pprust.rs | 6 +- src/libsyntax/visit.rs | 3 +- 19 files changed, 77 insertions(+), 216 deletions(-) diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 71d29bca401cc..70bad90aea1c0 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -15,7 +15,7 @@ pub use self::AbiArchitecture::*; use std::fmt; -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum Os { OsWindows, OsMacos, @@ -26,9 +26,7 @@ pub enum Os { OsDragonfly, } -impl Copy for Os {} - -#[deriving(PartialEq, Eq, Hash, Encodable, Decodable, Clone)] +#[deriving(Copy, PartialEq, Eq, Hash, Encodable, Decodable, Clone)] pub enum Abi { // NB: This ordering MUST match the AbiDatas array below. // (This is ensured by the test indices_are_correct().) @@ -48,10 +46,8 @@ pub enum Abi { RustCall, } -impl Copy for Abi {} - #[allow(non_camel_case_types)] -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum Architecture { X86, X86_64, @@ -60,8 +56,7 @@ pub enum Architecture { Mipsel } -impl Copy for Architecture {} - +#[deriving(Copy)] pub struct AbiData { abi: Abi, @@ -69,8 +64,7 @@ pub struct AbiData { name: &'static str, } -impl Copy for AbiData {} - +#[deriving(Copy)] pub enum AbiArchitecture { /// Not a real ABI (e.g., intrinsic) RustArch, @@ -80,9 +74,6 @@ pub enum AbiArchitecture { Archs(u32) } -#[allow(non_upper_case_globals)] -impl Copy for AbiArchitecture {} - #[allow(non_upper_case_globals)] static AbiDatas: &'static [AbiData] = &[ // Platform-specific ABIs diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index d4860766d4744..be8f32bc4d5d8 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -80,14 +80,12 @@ use serialize::{Encodable, Decodable, Encoder, Decoder}; /// table) and a SyntaxContext to track renaming and /// macro expansion per Flatt et al., "Macros /// That Work Together" -#[deriving(Clone, Hash, PartialOrd, Eq, Ord)] +#[deriving(Clone, Copy, Hash, PartialOrd, Eq, Ord)] pub struct Ident { pub name: Name, pub ctxt: SyntaxContext } -impl Copy for Ident {} - impl Ident { /// Construct an identifier with the given name and an empty context: pub fn new(name: Name) -> Ident { Ident {name: name, ctxt: EMPTY_CTXT}} @@ -160,11 +158,9 @@ pub const ILLEGAL_CTXT : SyntaxContext = 1; /// A name is a part of an identifier, representing a string or gensym. It's /// the result of interning. -#[deriving(Eq, Ord, PartialEq, PartialOrd, Hash, Encodable, Decodable, Clone)] +#[deriving(Copy, Eq, Ord, PartialEq, PartialOrd, Hash, Encodable, Decodable, Clone)] pub struct Name(pub u32); -impl Copy for Name {} - impl Name { pub fn as_str<'a>(&'a self) -> &'a str { unsafe { @@ -201,15 +197,13 @@ impl, E> Decodable for Ident { /// Function name (not all functions have names) pub type FnIdent = Option; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct Lifetime { pub id: NodeId, pub span: Span, pub name: Name } -impl Copy for Lifetime {} - #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct LifetimeDef { pub lifetime: Lifetime, @@ -353,14 +347,12 @@ pub type CrateNum = u32; pub type NodeId = u32; -#[deriving(Clone, Eq, Ord, PartialOrd, PartialEq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, Eq, Ord, PartialOrd, PartialEq, Encodable, Decodable, Hash, Show)] pub struct DefId { pub krate: CrateNum, pub node: NodeId, } -impl Copy for DefId {} - /// Item definitions in the currently-compiled crate would have the CrateNum /// LOCAL_CRATE in their DefId. pub const LOCAL_CRATE: CrateNum = 0; @@ -513,15 +505,13 @@ pub struct FieldPat { pub is_shorthand: bool, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum BindingMode { BindByRef(Mutability), BindByValue(Mutability), } -impl Copy for BindingMode {} - -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum PatWildKind { /// Represents the wildcard pattern `_` PatWildSingle, @@ -530,8 +520,6 @@ pub enum PatWildKind { PatWildMulti, } -impl Copy for PatWildKind {} - #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum Pat_ { /// Represents a wildcard pattern (either `_` or `..`) @@ -561,15 +549,13 @@ pub enum Pat_ { PatMac(Mac), } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum Mutability { MutMutable, MutImmutable, } -impl Copy for Mutability {} - -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum BinOp { BiAdd, BiSub, @@ -591,9 +577,7 @@ pub enum BinOp { BiGt, } -impl Copy for BinOp {} - -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum UnOp { UnUniq, UnDeref, @@ -601,8 +585,6 @@ pub enum UnOp { UnNeg } -impl Copy for UnOp {} - pub type Stmt = Spanned; #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] @@ -634,14 +616,12 @@ pub enum MacStmtStyle { /// Where a local declaration came from: either a true `let ... = /// ...;`, or one desugared from the pattern of a for loop. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum LocalSource { LocalLet, LocalFor, } -impl Copy for LocalSource {} - // FIXME (pending discussion of #1697, #2178...): local should really be // a refinement on pat. /// Local represents a `let` statement, e.g., `let : = ;` @@ -683,22 +663,18 @@ pub struct Field { pub type SpannedIdent = Spanned; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), } -impl Copy for BlockCheckMode {} - -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum UnsafeSource { CompilerGenerated, UserProvided, } -impl Copy for UnsafeSource {} - #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct Expr { pub id: NodeId, @@ -775,23 +751,19 @@ pub struct QPath { pub item_name: Ident, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum MatchSource { MatchNormal, MatchIfLetDesugar, MatchWhileLetDesugar, } -impl Copy for MatchSource {} - -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum CaptureClause { CaptureByValue, CaptureByRef, } -impl Copy for CaptureClause {} - /// A delimited sequence of token trees #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct Delimited { @@ -842,14 +814,12 @@ pub struct SequenceRepetition { /// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star) /// for token sequences. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum KleeneOp { ZeroOrMore, OneOrMore, } -impl Copy for KleeneOp {} - /// When the main rust parser encounters a syntax-extension invocation, it /// parses the arguments to the invocation as a token-tree. This is a very /// loose structure, such that all sorts of different AST-fragments can @@ -959,24 +929,20 @@ pub enum Mac_ { MacInvocTT(Path, Vec , SyntaxContext), // new macro-invocation } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum StrStyle { CookedStr, RawStr(uint) } -impl Copy for StrStyle {} - pub type Lit = Spanned; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum Sign { Minus, Plus } -impl Copy for Sign {} - impl Sign where T: Int { pub fn new(n: T) -> Sign { if n < Int::zero() { @@ -987,15 +953,13 @@ impl Sign where T: Int { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum LitIntType { SignedIntLit(IntTy, Sign), UnsignedIntLit(UintTy), UnsuffixedIntLit(Sign) } -impl Copy for LitIntType {} - impl LitIntType { pub fn suffix_len(&self) -> uint { match *self { @@ -1082,7 +1046,7 @@ pub struct Typedef { pub typ: P, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)] pub enum IntTy { TyI, TyI8, @@ -1091,8 +1055,6 @@ pub enum IntTy { TyI64, } -impl Copy for IntTy {} - impl fmt::Show for IntTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", ast_util::int_ty_to_string(*self, None)) @@ -1109,7 +1071,7 @@ impl IntTy { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)] pub enum UintTy { TyU, TyU8, @@ -1118,8 +1080,6 @@ pub enum UintTy { TyU64, } -impl Copy for UintTy {} - impl UintTy { pub fn suffix_len(&self) -> uint { match *self { @@ -1136,14 +1096,12 @@ impl fmt::Show for UintTy { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)] pub enum FloatTy { TyF32, TyF64, } -impl Copy for FloatTy {} - impl fmt::Show for FloatTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", ast_util::float_ty_to_string(*self)) @@ -1177,7 +1135,7 @@ pub struct Ty { } /// Not represented directly in the AST, referred to by name through a ty_path. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum PrimTy { TyInt(IntTy), TyUint(UintTy), @@ -1187,16 +1145,12 @@ pub enum PrimTy { TyChar } -impl Copy for PrimTy {} - -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)] pub enum Onceness { Once, Many } -impl Copy for Onceness {} - impl fmt::Show for Onceness { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { @@ -1259,14 +1213,12 @@ pub enum Ty_ { TyInfer, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum AsmDialect { AsmAtt, AsmIntel } -impl Copy for AsmDialect {} - #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct InlineAsm { pub asm: InternedString, @@ -1433,14 +1385,12 @@ pub struct Variant_ { pub type Variant = Spanned; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum PathListItem_ { PathListIdent { name: Ident, id: NodeId }, PathListMod { id: NodeId } } -impl Copy for PathListItem_ {} - impl PathListItem_ { pub fn id(&self) -> NodeId { match *self { @@ -1494,19 +1444,15 @@ pub type Attribute = Spanned; /// Distinguishes between Attributes that decorate items and Attributes that /// are contained as statements within items. These two cases need to be /// distinguished for pretty-printing. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum AttrStyle { AttrOuter, AttrInner, } -impl Copy for AttrStyle {} - -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct AttrId(pub uint); -impl Copy for AttrId {} - /// Doc-comments are promoted to attributes that have is_sugared_doc = true #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct Attribute_ { @@ -1536,14 +1482,12 @@ pub struct PolyTraitRef { pub trait_ref: TraitRef } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum Visibility { Public, Inherited, } -impl Copy for Visibility {} - impl Visibility { pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility { match self { @@ -1572,15 +1516,13 @@ impl StructField_ { pub type StructField = Spanned; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum StructFieldKind { NamedField(Ident, Visibility), /// Element of a tuple-like struct UnnamedField(Visibility), } -impl Copy for StructFieldKind {} - impl StructFieldKind { pub fn is_unnamed(&self) -> bool { match *self { @@ -1682,15 +1624,13 @@ impl ForeignItem_ { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum UnboxedClosureKind { FnUnboxedClosureKind, FnMutUnboxedClosureKind, FnOnceUnboxedClosureKind, } -impl Copy for UnboxedClosureKind {} - /// The data we save and restore about an inlined item or method. This is not /// part of the AST that we parse from a file, but it becomes part of the tree /// that we trans. diff --git a/src/libsyntax/ast_map/blocks.rs b/src/libsyntax/ast_map/blocks.rs index 6decfd1c3addc..7c89245f53ef7 100644 --- a/src/libsyntax/ast_map/blocks.rs +++ b/src/libsyntax/ast_map/blocks.rs @@ -41,10 +41,9 @@ use visit; /// - The default implementation for a trait method. /// /// To construct one, use the `Code::from_node` function. +#[deriving(Copy)] pub struct FnLikeNode<'a> { node: ast_map::Node<'a> } -impl<'a> Copy for FnLikeNode<'a> {} - /// MaybeFnLike wraps a method that indicates if an object /// corresponds to some FnLikeNode. pub trait MaybeFnLike { fn is_fn_like(&self) -> bool; } @@ -82,13 +81,12 @@ impl MaybeFnLike for ast::Expr { /// Carries either an FnLikeNode or a Block, as these are the two /// constructs that correspond to "code" (as in, something from which /// we can construct a control-flow graph). +#[deriving(Copy)] pub enum Code<'a> { FnLikeCode(FnLikeNode<'a>), BlockCode(&'a Block), } -impl<'a> Copy for Code<'a> {} - impl<'a> Code<'a> { pub fn id(&self) -> ast::NodeId { match *self { diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 6089f39e828b1..a95c9e199060b 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -32,14 +32,12 @@ use std::slice; pub mod blocks; -#[deriving(Clone, PartialEq)] +#[deriving(Clone, Copy, PartialEq)] pub enum PathElem { PathMod(Name), PathName(Name) } -impl Copy for PathElem {} - impl PathElem { pub fn name(&self) -> Name { match *self { @@ -102,7 +100,7 @@ pub fn path_to_string>(path: PI) -> String { }).to_string() } -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum Node<'ast> { NodeItem(&'ast Item), NodeForeignItem(&'ast ForeignItem), @@ -122,11 +120,9 @@ pub enum Node<'ast> { NodeLifetime(&'ast Lifetime), } -impl<'ast> Copy for Node<'ast> {} - /// Represents an entry and its parent Node ID /// The odd layout is to bring down the total size. -#[deriving(Show)] +#[deriving(Copy, Show)] enum MapEntry<'ast> { /// Placeholder for holes in the map. NotPresent, @@ -151,8 +147,6 @@ enum MapEntry<'ast> { RootInlinedParent(&'ast InlinedParent) } -impl<'ast> Copy for MapEntry<'ast> {} - impl<'ast> Clone for MapEntry<'ast> { fn clone(&self) -> MapEntry<'ast> { *self diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 5243f07f32749..02771809ae6a7 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -343,14 +343,12 @@ pub fn empty_generics() -> Generics { // ______________________________________________________________________ // Enumerating the IDs which appear in an AST -#[deriving(Encodable, Decodable, Show)] +#[deriving(Copy, Encodable, Decodable, Show)] pub struct IdRange { pub min: NodeId, pub max: NodeId, } -impl Copy for IdRange {} - impl IdRange { pub fn max() -> IdRange { IdRange { diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 598da6a5df0cb..127cc5ed51d11 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -277,7 +277,7 @@ pub fn find_crate_name(attrs: &[Attribute]) -> Option { first_attr_value_str_by_name(attrs, "crate_name") } -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum InlineAttr { InlineNone, InlineHint, @@ -285,8 +285,6 @@ pub enum InlineAttr { InlineNever, } -impl Copy for InlineAttr {} - /// Determine what `#[inline]` attribute is present in `attrs`, if any. pub fn find_inline_attr(attrs: &[Attribute]) -> InlineAttr { // FIXME (#2809)---validate the usage of #[inline] and #[inline] @@ -349,7 +347,7 @@ pub struct Stability { } /// The available stability levels. -#[deriving(Encodable,Decodable,PartialEq,PartialOrd,Clone,Show)] +#[deriving(Copy,Encodable,Decodable,PartialEq,PartialOrd,Clone,Show)] pub enum StabilityLevel { Deprecated, Experimental, @@ -359,8 +357,6 @@ pub enum StabilityLevel { Locked } -impl Copy for StabilityLevel {} - pub fn find_stability_generic<'a, AM: AttrMetaMethods, I: Iterator<&'a AM>> @@ -468,7 +464,7 @@ fn int_type_of_word(s: &str) -> Option { } } -#[deriving(PartialEq, Show, Encodable, Decodable)] +#[deriving(Copy, PartialEq, Show, Encodable, Decodable)] pub enum ReprAttr { ReprAny, ReprInt(Span, IntType), @@ -476,8 +472,6 @@ pub enum ReprAttr { ReprPacked, } -impl Copy for ReprAttr {} - impl ReprAttr { pub fn is_ffi_safe(&self) -> bool { match *self { @@ -489,14 +483,12 @@ impl ReprAttr { } } -#[deriving(Eq, Hash, PartialEq, Show, Encodable, Decodable)] +#[deriving(Copy, Eq, Hash, PartialEq, Show, Encodable, Decodable)] pub enum IntType { SignedInt(ast::IntTy), UnsignedInt(ast::UintTy) } -impl Copy for IntType {} - impl IntType { #[inline] pub fn is_signed(self) -> bool { diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 17cafc2441f9d..b7c0678cf139c 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -31,19 +31,15 @@ pub trait Pos { /// A byte offset. Keep this small (currently 32-bits), as AST contains /// a lot of them. -#[deriving(Clone, PartialEq, Eq, Hash, PartialOrd, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Show)] pub struct BytePos(pub u32); -impl Copy for BytePos {} - /// A character offset. Because of multibyte utf8 characters, a byte offset /// is not equivalent to a character offset. The CodeMap will convert BytePos /// values to CharPos values as necessary. -#[deriving(PartialEq, Hash, PartialOrd, Show)] +#[deriving(Copy, PartialEq, Hash, PartialOrd, Show)] pub struct CharPos(pub uint); -impl Copy for CharPos {} - // FIXME: Lots of boilerplate in these impls, but so far my attempts to fix // have been unsuccessful @@ -121,7 +117,7 @@ impl Sub for CharPos { /// are *absolute* positions from the beginning of the codemap, not positions /// relative to FileMaps. Methods on the CodeMap can be used to relate spans back /// to the original source. -#[deriving(Clone, Show, Hash)] +#[deriving(Clone, Copy, Show, Hash)] pub struct Span { pub lo: BytePos, pub hi: BytePos, @@ -130,18 +126,14 @@ pub struct Span { pub expn_id: ExpnId } -impl Copy for Span {} - pub const DUMMY_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_id: NO_EXPANSION }; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct Spanned { pub node: T, pub span: Span, } -impl Copy for Spanned {} - impl PartialEq for Span { fn eq(&self, other: &Span) -> bool { return (*self).lo == (*other).lo && (*self).hi == (*other).hi; @@ -219,7 +211,7 @@ pub struct FileMapAndLine { pub fm: Rc, pub line: uint } pub struct FileMapAndBytePos { pub fm: Rc, pub pos: BytePos } /// The syntax with which a macro was invoked. -#[deriving(Clone, Hash, Show)] +#[deriving(Clone, Copy, Hash, Show)] pub enum MacroFormat { /// e.g. #[deriving(...)] MacroAttribute, @@ -227,8 +219,6 @@ pub enum MacroFormat { MacroBang } -impl Copy for MacroFormat {} - #[deriving(Clone, Hash, Show)] pub struct NameAndSpan { /// The name of the macro that was invoked to create the thing @@ -264,11 +254,9 @@ pub struct ExpnInfo { pub callee: NameAndSpan } -#[deriving(PartialEq, Eq, Clone, Show, Hash, Encodable, Decodable)] +#[deriving(Copy, PartialEq, Eq, Clone, Show, Hash, Encodable, Decodable)] pub struct ExpnId(u32); -impl Copy for ExpnId {} - pub const NO_EXPANSION: ExpnId = ExpnId(-1); impl ExpnId { @@ -290,6 +278,7 @@ pub struct FileLines { } /// Identifies an offset of a multi-byte character in a FileMap +#[deriving(Copy)] pub struct MultiByteChar { /// The absolute offset of the character in the CodeMap pub pos: BytePos, @@ -297,8 +286,6 @@ pub struct MultiByteChar { pub bytes: uint, } -impl Copy for MultiByteChar {} - /// A single source in the CodeMap pub struct FileMap { /// The name of the file that the source came from, source that doesn't diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 3a81698792264..4d765f49acabd 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -28,7 +28,7 @@ use term; /// maximum number of lines we will print for each error; arbitrary. static MAX_LINES: uint = 6u; -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub enum RenderSpan { /// A FullSpan renders with both with an initial line for the /// message, prefixed by file:linenum, followed by a summary of @@ -40,8 +40,6 @@ pub enum RenderSpan { FileLine(Span), } -impl Copy for RenderSpan {} - impl RenderSpan { fn span(self) -> Span { match self { @@ -56,15 +54,13 @@ impl RenderSpan { } } -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub enum ColorConfig { Auto, Always, Never } -impl Copy for ColorConfig {} - pub trait Emitter { fn emit(&mut self, cmsp: Option<(&codemap::CodeMap, Span)>, msg: &str, code: Option<&str>, lvl: Level); @@ -75,16 +71,14 @@ pub trait Emitter { /// This structure is used to signify that a task has panicked with a fatal error /// from the diagnostics. You can use this with the `Any` trait to figure out /// how a rustc task died (if so desired). +#[deriving(Copy)] pub struct FatalError; -impl Copy for FatalError {} - /// Signifies that the compiler died with an explicit call to `.bug` /// or `.span_bug` rather than a failed assertion, etc. +#[deriving(Copy)] pub struct ExplicitBug; -impl Copy for ExplicitBug {} - /// A span-handler is like a handler but also /// accepts span information for source-location /// reporting. @@ -228,7 +222,7 @@ pub fn mk_handler(e: Box) -> Handler { } } -#[deriving(PartialEq, Clone)] +#[deriving(Copy, PartialEq, Clone)] pub enum Level { Bug, Fatal, @@ -238,8 +232,6 @@ pub enum Level { Help, } -impl Copy for Level {} - impl fmt::Show for Level { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use std::fmt::Show; diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 354b53bfc01d0..3947a602809e6 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -223,13 +223,12 @@ impl MacResult for MacItems { /// Fill-in macro expansion result, to allow compilation to continue /// after hitting errors. +#[deriving(Copy)] pub struct DummyResult { expr_only: bool, span: Span } -impl Copy for DummyResult {} - impl DummyResult { /// Create a default MacResult that can be anything. /// diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index bd1962de56ed9..10e14e0c97564 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -83,12 +83,11 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, trait_def.expand(cx, mitem, item, push) } +#[deriving(Copy)] pub enum OrderingOp { PartialCmpOp, LtOp, LeOp, GtOp, GeOp, } -impl Copy for OrderingOp {} - pub fn some_ordering_collapsed(cx: &mut ExtCtxt, span: Span, op: OrderingOp, diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs index 33936e6213f45..ae979020bc7e5 100644 --- a/src/libsyntax/ext/mtwt.rs +++ b/src/libsyntax/ext/mtwt.rs @@ -39,7 +39,7 @@ pub struct SCTable { rename_memo: RefCell>, } -#[deriving(PartialEq, Encodable, Decodable, Hash, Show)] +#[deriving(Copy, PartialEq, Encodable, Decodable, Hash, Show)] pub enum SyntaxContext_ { EmptyCtxt, Mark (Mrk,SyntaxContext), @@ -56,8 +56,6 @@ pub enum SyntaxContext_ { IllegalCtxt } -impl Copy for SyntaxContext_ {} - /// A list of ident->name renamings pub type RenameList = Vec<(Ident, Name)>; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 9656629e14d77..0e0a87c74f849 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -97,6 +97,7 @@ enum Status { } /// A set of features to be used by later passes. +#[deriving(Copy)] pub struct Features { pub default_type_params: bool, pub unboxed_closures: bool, @@ -107,8 +108,6 @@ pub struct Features { pub opt_out_copy: bool, } -impl Copy for Features {} - impl Features { pub fn new() -> Features { Features { diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index a17d66476c08c..95bae63f58f65 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -24,7 +24,7 @@ use std::str; use std::string::String; use std::uint; -#[deriving(Clone, PartialEq)] +#[deriving(Clone, Copy, PartialEq)] pub enum CommentStyle { /// No code on either side of each line of the comment Isolated, @@ -36,8 +36,6 @@ pub enum CommentStyle { BlankLine, } -impl Copy for CommentStyle {} - #[deriving(Clone)] pub struct Comment { pub style: CommentStyle, diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 3a7cc77515dbe..a6ddcbf9ac41e 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -22,7 +22,7 @@ use parse::token; use ptr::P; /// The specific types of unsupported syntax -#[deriving(PartialEq, Eq, Hash)] +#[deriving(Copy, PartialEq, Eq, Hash)] pub enum ObsoleteSyntax { ObsoleteOwnedType, ObsoleteOwnedExpr, @@ -36,8 +36,6 @@ pub enum ObsoleteSyntax { ObsoleteProcExpr, } -impl Copy for ObsoleteSyntax {} - pub trait ParserObsoleteMethods { /// Reports an obsolete syntax non-fatal error. fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c234c172fd8a6..3ad224b93ce96 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -104,7 +104,7 @@ type ItemInfo = (Ident, Item_, Option >); /// How to parse a path. There are four different kinds of paths, all of which /// are parsed somewhat differently. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum PathParsingMode { /// A path with no type parameters; e.g. `foo::bar::Baz` NoTypesAllowed, @@ -116,8 +116,6 @@ pub enum PathParsingMode { LifetimeAndTypesWithColons, } -impl Copy for PathParsingMode {} - enum ItemOrViewItem { /// Indicates a failure to parse any kind of item. The attributes are /// returned. diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 641239f1f8b8d..dad369792d7a1 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -28,7 +28,7 @@ use std::path::BytesContainer; use std::rc::Rc; #[allow(non_camel_case_types)] -#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Eq, Hash, Show)] pub enum BinOpToken { Plus, Minus, @@ -42,10 +42,8 @@ pub enum BinOpToken { Shr, } -impl Copy for BinOpToken {} - /// A delimeter token -#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Eq, Hash, Show)] pub enum DelimToken { /// A round parenthesis: `(` or `)` Paren, @@ -55,16 +53,14 @@ pub enum DelimToken { Brace, } -impl Copy for DelimToken {} - -#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Eq, Hash, Show)] pub enum IdentStyle { /// `::` follows the identifier with no whitespace in-between. ModName, Plain, } -#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Eq, Hash, Show)] pub enum Lit { Byte(ast::Name), Char(ast::Name), @@ -89,10 +85,6 @@ impl Lit { } } -impl Copy for Lit {} - -impl Copy for IdentStyle {} - #[allow(non_camel_case_types)] #[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] pub enum Token { @@ -438,13 +430,12 @@ macro_rules! declare_special_idents_and_keywords {( pub use self::Keyword::*; use ast; + #[deriving(Copy)] pub enum Keyword { $( $sk_variant, )* $( $rk_variant, )* } - impl Copy for Keyword {} - impl Keyword { pub fn to_name(&self) -> ast::Name { match *self { diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index c4e040a0f7c1a..bfa47a46e7465 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -66,30 +66,24 @@ pub use self::Token::*; use std::io; use std::string; -#[deriving(Clone, PartialEq)] +#[deriving(Clone, Copy, PartialEq)] pub enum Breaks { Consistent, Inconsistent, } -impl Copy for Breaks {} - -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct BreakToken { offset: int, blank_space: int } -impl Copy for BreakToken {} - -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub struct BeginToken { offset: int, breaks: Breaks } -impl Copy for BeginToken {} - #[deriving(Clone)] pub enum Token { String(string::String, int), @@ -153,20 +147,18 @@ pub fn buf_str(toks: Vec, return s.into_string(); } +#[deriving(Copy)] pub enum PrintStackBreak { Fits, Broken(Breaks), } -impl Copy for PrintStackBreak {} - +#[deriving(Copy)] pub struct PrintStackElem { offset: int, pbreak: PrintStackBreak } -impl Copy for PrintStackElem {} - static SIZE_INFINITY: int = 0xffff; pub fn mk_printer(out: Box, linewidth: uint) -> Printer { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 1dd61a5ce1943..d2cc0cba3173c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -45,19 +45,17 @@ pub trait PpAnn { fn post(&self, _state: &mut State, _node: AnnNode) -> IoResult<()> { Ok(()) } } +#[deriving(Copy)] pub struct NoAnn; -impl Copy for NoAnn {} - impl PpAnn for NoAnn {} +#[deriving(Copy)] pub struct CurrentCommentAndLiteral { cur_cmnt: uint, cur_lit: uint, } -impl Copy for CurrentCommentAndLiteral {} - pub struct State<'a> { pub s: pp::Printer, cm: Option<&'a CodeMap>, diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 5a1a186c74c4e..b89e9a59349ce 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -32,6 +32,7 @@ use codemap::Span; use ptr::P; use owned_slice::OwnedSlice; +#[deriving(Copy)] pub enum FnKind<'a> { /// fn foo() or extern "Abi" fn foo() FkItemFn(Ident, &'a Generics, Unsafety, Abi), @@ -44,8 +45,6 @@ pub enum FnKind<'a> { FkFnBlock, } -impl<'a> Copy for FnKind<'a> {} - /// Each method of the Visitor trait is a hook to be potentially /// overridden. Each method's default implementation recursively visits /// the substructure of the input via the corresponding `walk` method; From 64234b3541e032302206056e075d500eacec5f35 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:33:35 -0500 Subject: [PATCH 20/23] libterm: use `#[deriving(Copy)]` --- src/libterm/lib.rs | 4 +--- src/libterm/terminfo/parm.rs | 15 ++++----------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index e8824b1ad2ca1..a4ebcfe8a568b 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -165,13 +165,13 @@ pub mod color { /// Terminal attributes pub mod attr { pub use self::Attr::*; - use std::kinds::Copy; /// Terminal attributes for use with term.attr(). /// /// Most attributes can only be turned on and must be turned off with term.reset(). /// The ones that can be turned off explicitly take a boolean value. /// Color is also represented as an attribute for convenience. + #[deriving(Copy)] pub enum Attr { /// Bold (or possibly bright) mode Bold, @@ -194,8 +194,6 @@ pub mod attr { /// Convenience attribute to set the background color BackgroundColor(super::color::Color) } - - impl Copy for Attr {} } /// A terminal with similar capabilities to an ANSI Terminal diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index c81bff6a1aeb3..4ecbc54c59089 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -16,7 +16,7 @@ use self::FormatState::*; use self::FormatOp::*; use std::mem::replace; -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] enum States { Nothing, Percent, @@ -33,17 +33,13 @@ enum States { SeekIfEndPercent(int) } -impl Copy for States {} - -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] enum FormatState { FormatStateFlags, FormatStateWidth, FormatStatePrecision } -impl Copy for FormatState {} - /// Types of parameters a capability can use #[allow(missing_docs)] #[deriving(Clone)] @@ -446,7 +442,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) Ok(output) } -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] struct Flags { width: uint, precision: uint, @@ -456,8 +452,6 @@ struct Flags { space: bool } -impl Copy for Flags {} - impl Flags { fn new() -> Flags { Flags{ width: 0, precision: 0, alternate: false, @@ -465,6 +459,7 @@ impl Flags { } } +#[deriving(Copy)] enum FormatOp { FormatDigit, FormatOctal, @@ -473,8 +468,6 @@ enum FormatOp { FormatString } -impl Copy for FormatOp {} - impl FormatOp { fn from_char(c: char) -> FormatOp { match c { From ce9243776932b69359226491187d5d9fc7c2d7b2 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:34:08 -0500 Subject: [PATCH 21/23] libtest: use `#[deriving(Copy)]` --- src/libtest/lib.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 56af8785a76d4..5b04a1fed896c 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -110,15 +110,13 @@ impl Show for TestName { } } -#[deriving(Clone)] +#[deriving(Clone, Copy)] enum NamePadding { PadNone, PadOnLeft, PadOnRight, } -impl Copy for NamePadding {} - impl TestDesc { fn padded_name(&self, column_count: uint, align: NamePadding) -> String { let mut name = String::from_str(self.name.as_slice()); @@ -215,14 +213,12 @@ pub struct TestDescAndFn { pub testfn: TestFn, } -#[deriving(Clone, Encodable, Decodable, PartialEq, Show)] +#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Show)] pub struct Metric { value: f64, noise: f64 } -impl Copy for Metric {} - impl Metric { pub fn new(value: f64, noise: f64) -> Metric { Metric {value: value, noise: noise} @@ -240,7 +236,7 @@ impl Clone for MetricMap { } /// Analysis of a single change in metric -#[deriving(PartialEq, Show)] +#[deriving(Copy, PartialEq, Show)] pub enum MetricChange { LikelyNoise, MetricAdded, @@ -249,8 +245,6 @@ pub enum MetricChange { Regression(f64) } -impl Copy for MetricChange {} - pub type MetricDiff = BTreeMap; // The default console test runner. It accepts the command line @@ -287,14 +281,13 @@ pub fn test_main_static(args: &[String], tests: &[TestDescAndFn]) { test_main(args, owned_tests) } +#[deriving(Copy)] pub enum ColorConfig { AutoColor, AlwaysColor, NeverColor, } -impl Copy for ColorConfig {} - pub struct TestOpts { pub filter: Option, pub run_ignored: bool, From 4c6e76b7c8823b3fe259e7f8da21de2c86def554 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:34:36 -0500 Subject: [PATCH 22/23] libtime: use `#[deriving(Copy)]` --- src/libtime/lib.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs index 4129086e9ec97..1b7f5cdc4af51 100644 --- a/src/libtime/lib.rs +++ b/src/libtime/lib.rs @@ -76,14 +76,12 @@ mod imp { } /// A record specifying a time value in seconds and nanoseconds. -#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable, Show)] pub struct Timespec { pub sec: i64, pub nsec: i32, } -impl Copy for Timespec {} - /* * Timespec assumes that pre-epoch Timespecs have negative sec and positive * nsec fields. Darwin's and Linux's struct timespec functions handle pre- @@ -268,7 +266,7 @@ pub fn tzset() { /// also called a broken-down time value. // FIXME: use c_int instead of i32? #[repr(C)] -#[deriving(Clone, PartialEq, Eq, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Show)] pub struct Tm { /// Seconds after the minute - [0, 60] pub tm_sec: i32, @@ -309,8 +307,6 @@ pub struct Tm { pub tm_nsec: i32, } -impl Copy for Tm {} - pub fn empty_tm() -> Tm { Tm { tm_sec: 0_i32, @@ -452,7 +448,7 @@ impl Tm { } } -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum ParseError { InvalidSecond, InvalidMinute, @@ -470,8 +466,6 @@ pub enum ParseError { UnexpectedCharacter(char, char), } -impl Copy for ParseError {} - impl Show for ParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { From f975b10310b2f38a5ac1e50f30778b85ed963849 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 19 Dec 2014 08:09:11 -0500 Subject: [PATCH 23/23] windows: remove unused import --- src/libstd/rt/unwind.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 4d5feaa2454b7..f572141642cbf 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -384,7 +384,6 @@ pub mod eabi { pub use self::EXCEPTION_DISPOSITION::*; use rt::libunwind as uw; use libc::{c_void, c_int}; - use kinds::Copy; #[repr(C)] #[allow(missing_copy_implementations)]