Skip to content

Small deriving-related cleanups #5513

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from Mar 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ pub mod rt;
// can be resolved within libcore.
#[doc(hidden)]
pub mod core {
pub use clone;
pub use cmp;
pub use condition;
pub use option;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use result;
use vec;

/// The either type
#[deriving(Eq)]
#[deriving(Clone, Eq)]
pub enum Either<T, U> {
Left(T),
Right(U)
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use iter::{BaseIter, MutableIter};
#[cfg(test)] use str;

/// The option type
#[deriving(Eq)]
#[deriving(Clone, Eq)]
pub enum Option<T> {
None,
Some(T),
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use option::{None, Option, Some};
use str;
use to_str::ToStr;

#[deriving(Eq)]
#[deriving(Clone, Eq)]
pub struct WindowsPath {
host: Option<~str>,
device: Option<~str>,
Expand All @@ -32,7 +32,7 @@ pub fn WindowsPath(s: &str) -> WindowsPath {
GenericPath::from_str(s)
}

#[deriving(Eq)]
#[deriving(Clone, Eq)]
pub struct PosixPath {
is_absolute: bool,
components: ~[~str],
Expand Down
9 changes: 1 addition & 8 deletions src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ bounded and unbounded protocols allows for less code duplication.

*/

use cmp::Eq;
use cast::{forget, reinterpret_cast, transmute};
use cell::Cell;
use either::{Either, Left, Right};
Expand All @@ -103,20 +102,14 @@ macro_rules! move_it (
)

#[doc(hidden)]
#[deriving(Eq)]
enum State {
Empty,
Full,
Blocked,
Terminated
}

impl Eq for State {
fn eq(&self, other: &State) -> bool {
((*self) as uint) == ((*other) as uint)
}
fn ne(&self, other: &State) -> bool { !(*self).eq(other) }
}

pub struct BufferHeader {
// Tracks whether this buffer needs to be freed. We can probably
// get away with restricting it to 0 or 1, if we're careful.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use option::{None, Option, Some};
use vec;

/// The result type
#[deriving(Eq)]
#[deriving(Clone, Eq)]
pub enum Result<T, U> {
/// Contains the successful result value
Ok(T),
Expand Down
11 changes: 1 addition & 10 deletions src/libcore/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,12 @@ pub enum Task {
* If you wish for this result's delivery to block until all linked and/or
* children tasks complete, recommend using a result future.
*/
#[deriving(Eq)]
pub enum TaskResult {
Success,
Failure,
}

impl Eq for TaskResult {
fn eq(&self, other: &TaskResult) -> bool {
match ((*self), (*other)) {
(Success, Success) | (Failure, Failure) => true,
(Success, _) | (Failure, _) => false
}
}
fn ne(&self, other: &TaskResult) -> bool { !(*self).eq(other) }
}

/// Scheduler modes
#[deriving(Eq)]
pub enum SchedMode {
Expand Down
7 changes: 1 addition & 6 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2533,12 +2533,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
impl<A:Clone> Clone for ~[A] {
#[inline]
fn clone(&self) -> ~[A] {
let mut dolly = ~[];
vec::reserve(&mut dolly, self.len());
for self.each |item| {
dolly.push(item.clone());
}
return dolly;
self.map(|item| item.clone())
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/libstd/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,9 @@ priv fn get_radix_base(radix: uint) -> (uint, uint) {
}

/// A Sign is a BigInt's composing element.
#[deriving(Eq)]
pub enum Sign { Minus, Zero, Plus }

impl Eq for Sign {
fn eq(&self, other: &Sign) -> bool { self.cmp(other) == 0 }
fn ne(&self, other: &Sign) -> bool { self.cmp(other) != 0 }
}

impl Ord for Sign {
fn lt(&self, other: &Sign) -> bool { self.cmp(other) < 0 }
fn le(&self, other: &Sign) -> bool { self.cmp(other) <= 0 }
Expand Down
10 changes: 1 addition & 9 deletions src/libstd/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub enum Json {
pub type List = ~[Json];
pub type Object = LinearMap<~str, Json>;

#[deriving(Eq)]
pub struct Error {
line: uint,
col: uint,
Expand Down Expand Up @@ -1060,15 +1061,6 @@ impl Ord for Json {
fn gt(&self, other: &Json) -> bool { (*other).lt(&(*self)) }
}

impl Eq for Error {
fn eq(&self, other: &Error) -> bool {
(*self).line == other.line &&
(*self).col == other.col &&
(*self).msg == other.msg
}
fn ne(&self, other: &Error) -> bool { !(*self).eq(other) }
}

trait ToJson { fn to_json(&self) -> Json; }

impl ToJson for Json {
Expand Down
27 changes: 2 additions & 25 deletions src/libstd/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub mod rustrt {
/// A record specifying a time value in seconds and nanoseconds.
#[auto_encode]
#[auto_decode]
#[deriving(Eq)]
pub struct Timespec { sec: i64, nsec: i32 }

/*
Expand All @@ -57,13 +58,6 @@ pub impl Timespec {
}
}

impl Eq for Timespec {
fn eq(&self, other: &Timespec) -> bool {
self.sec == other.sec && self.nsec == other.nsec
}
fn ne(&self, other: &Timespec) -> bool { !self.eq(other) }
}

impl Ord for Timespec {
fn lt(&self, other: &Timespec) -> bool {
self.sec < other.sec ||
Expand Down Expand Up @@ -117,6 +111,7 @@ pub fn tzset() {

#[auto_encode]
#[auto_decode]
#[deriving(Eq)]
pub struct Tm {
tm_sec: i32, // seconds after the minute ~[0-60]
tm_min: i32, // minutes after the hour ~[0-59]
Expand All @@ -132,24 +127,6 @@ pub struct Tm {
tm_nsec: i32, // nanoseconds
}

impl Eq for Tm {
fn eq(&self, other: &Tm) -> bool {
self.tm_sec == (*other).tm_sec &&
self.tm_min == (*other).tm_min &&
self.tm_hour == (*other).tm_hour &&
self.tm_mday == (*other).tm_mday &&
self.tm_mon == (*other).tm_mon &&
self.tm_year == (*other).tm_year &&
self.tm_wday == (*other).tm_wday &&
self.tm_yday == (*other).tm_yday &&
self.tm_isdst == (*other).tm_isdst &&
self.tm_gmtoff == (*other).tm_gmtoff &&
self.tm_zone == (*other).tm_zone &&
self.tm_nsec == (*other).tm_nsec
}
fn ne(&self, other: &Tm) -> bool { !self.eq(other) }
}

pub fn empty_tm() -> Tm {
Tm {
tm_sec: 0_i32,
Expand Down