Skip to content

Commit

Permalink
derive Eq and Clone impls where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
apasel422 committed Mar 28, 2013
1 parent f7f6013 commit f02ee42
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 303 deletions.
46 changes: 3 additions & 43 deletions src/librustc/middle/liveness.rs
Expand Up @@ -111,7 +111,6 @@ use middle::typeck;
use middle::moves;
use util::ppaux::ty_to_str;

use core::cmp;
use core::hashmap::linear::LinearMap;
use core::io::WriterUtil;
use core::io;
Expand All @@ -137,58 +136,19 @@ use syntax::{visit, ast_util};
// if it detects an outstanding loan (that is, the addr is taken).
pub type last_use_map = @mut LinearMap<node_id, @mut ~[node_id]>;

#[deriving(Eq)]
struct Variable(uint);
#[deriving(Eq)]
struct LiveNode(uint);

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

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

#[deriving(Eq)]
enum LiveNodeKind {
FreeVarNode(span),
ExprNode(span),
VarDefNode(span),
ExitNode
}

impl cmp::Eq for LiveNodeKind {
fn eq(&self, other: &LiveNodeKind) -> bool {
match (*self) {
FreeVarNode(e0a) => {
match (*other) {
FreeVarNode(e0b) => e0a == e0b,
_ => false
}
}
ExprNode(e0a) => {
match (*other) {
ExprNode(e0b) => e0a == e0b,
_ => false
}
}
VarDefNode(e0a) => {
match (*other) {
VarDefNode(e0b) => e0a == e0b,
_ => false
}
}
ExitNode => {
match (*other) {
ExitNode => true,
_ => false
}
}
}
}
fn ne(&self, other: &LiveNodeKind) -> bool { !(*self).eq(other) }
}

fn live_node_kind_to_str(lnk: LiveNodeKind, cx: ty::ctxt) -> ~str {
let cm = cx.sess.codemap;
match lnk {
Expand Down
9 changes: 1 addition & 8 deletions src/librustc/middle/trans/cabi_x86_64.rs
Expand Up @@ -18,13 +18,13 @@ use lib::llvm::struct_tys;
use middle::trans::common::*;
use middle::trans::cabi::*;

use core::cmp;
use core::libc::c_uint;
use core::option;
use core::option::Option;
use core::uint;
use core::vec;

#[deriving(Eq)]
enum x86_64_reg_class {
no_class,
integer_class,
Expand All @@ -40,13 +40,6 @@ enum x86_64_reg_class {
memory_class
}

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

fn is_sse(++c: x86_64_reg_class) -> bool {
return match c {
sse_fs_class | sse_fv_class |
Expand Down
9 changes: 1 addition & 8 deletions src/librustc/middle/trans/datum.rs
Expand Up @@ -104,7 +104,6 @@ use middle::ty;
use util::common::indenter;
use util::ppaux::ty_to_str;

use core::cmp;
use core::container::Set; // XXX: this should not be necessary
use core::to_bytes;
use core::uint;
Expand Down Expand Up @@ -140,6 +139,7 @@ pub struct DatumBlock {
datum: Datum,
}

#[deriving(Eq)]
pub enum DatumMode {
/// `val` is a pointer to the actual value (and thus has type *T)
ByRef,
Expand All @@ -158,13 +158,6 @@ pub impl DatumMode {
}
}

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

impl to_bytes::IterBytes for DatumMode {
fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
(*self as uint).iter_bytes(lsb0, f)
Expand Down
32 changes: 2 additions & 30 deletions src/librustc/middle/trans/expr.rs
Expand Up @@ -160,6 +160,7 @@ use syntax::codemap;
// These are passed around by the code generating functions to track the
// destination of a computation's value.

#[deriving(Eq)]
pub enum Dest {
SaveIn(ValueRef),
Ignore,
Expand All @@ -174,18 +175,6 @@ pub impl Dest {
}
}

impl cmp::Eq for Dest {
fn eq(&self, other: &Dest) -> bool {
match ((*self), (*other)) {
(SaveIn(e0a), SaveIn(e0b)) => e0a == e0b,
(Ignore, Ignore) => true,
(SaveIn(*), _) => false,
(Ignore, _) => false,
}
}
fn ne(&self, other: &Dest) -> bool { !(*self).eq(other) }
}

fn drop_and_cancel_clean(bcx: block, dat: Datum) -> block {
let bcx = dat.drop_val(bcx);
dat.cancel_clean(bcx);
Expand Down Expand Up @@ -1682,6 +1671,7 @@ fn float_cast(bcx: block, lldsttype: TypeRef, llsrctype: TypeRef,
} else { llsrc };
}

#[deriving(Eq)]
pub enum cast_kind {
cast_pointer,
cast_integral,
Expand All @@ -1690,24 +1680,6 @@ pub enum cast_kind {
cast_other,
}

impl cmp::Eq for cast_kind {
fn eq(&self, other: &cast_kind) -> bool {
match ((*self), (*other)) {
(cast_pointer, cast_pointer) => true,
(cast_integral, cast_integral) => true,
(cast_float, cast_float) => true,
(cast_enum, cast_enum) => true,
(cast_other, cast_other) => true,
(cast_pointer, _) => false,
(cast_integral, _) => false,
(cast_float, _) => false,
(cast_enum, _) => false,
(cast_other, _) => false,
}
}
fn ne(&self, other: &cast_kind) -> bool { !(*self).eq(other) }
}

pub fn cast_type_kind(t: ty::t) -> cast_kind {
match ty::get(t).sty {
ty::ty_float(*) => cast_float,
Expand Down
140 changes: 5 additions & 135 deletions src/librustc/middle/ty.rs
Expand Up @@ -76,6 +76,7 @@ pub struct method {
def_id: ast::def_id
}

#[deriving(Eq)]
pub struct mt {
ty: t,
mutbl: ast::mutability,
Expand Down Expand Up @@ -161,22 +162,9 @@ pub type opt_region_variance = Option<region_variance>;

#[auto_encode]
#[auto_decode]
#[deriving(Eq)]
pub enum region_variance { rv_covariant, rv_invariant, rv_contravariant }

impl cmp::Eq for region_variance {
fn eq(&self, other: &region_variance) -> bool {
match ((*self), (*other)) {
(rv_covariant, rv_covariant) => true,
(rv_invariant, rv_invariant) => true,
(rv_contravariant, rv_contravariant) => true,
(rv_covariant, _) => false,
(rv_invariant, _) => false,
(rv_contravariant, _) => false
}
}
fn ne(&self, other: &region_variance) -> bool { !(*self).eq(other) }
}

#[auto_encode]
#[auto_decode]
pub enum AutoAdjustment {
Expand Down Expand Up @@ -417,6 +405,7 @@ impl to_bytes::IterBytes for param_ty {
/// Representation of regions:
#[auto_encode]
#[auto_decode]
#[deriving(Eq)]
pub enum Region {
/// Bound regions are found (primarily) in function types. They indicate
/// region parameters that have yet to be replaced with actual regions
Expand Down Expand Up @@ -446,6 +435,7 @@ pub enum Region {

#[auto_encode]
#[auto_decode]
#[deriving(Eq)]
pub enum bound_region {
/// The self region for structs, impls (&T in a type defn or &'self T)
br_self,
Expand Down Expand Up @@ -585,6 +575,7 @@ pub enum type_err {
terr_float_mismatch(expected_found<ast::float_ty>)
}

#[deriving(Eq)]
pub enum param_bound {
bound_copy,
bound_durable,
Expand Down Expand Up @@ -4367,127 +4358,6 @@ pub fn get_impl_id(tcx: ctxt, trait_id: def_id, self_ty: t) -> def_id {
}
}

impl cmp::Eq for mt {
fn eq(&self, other: &mt) -> bool {
(*self).ty == (*other).ty && (*self).mutbl == (*other).mutbl
}
fn ne(&self, other: &mt) -> bool { !(*self).eq(other) }
}

impl cmp::Eq for Region {
fn eq(&self, other: &Region) -> bool {
match (*self) {
re_bound(e0a) => {
match (*other) {
re_bound(e0b) => e0a == e0b,
_ => false
}
}
re_free(e0a, e1a) => {
match (*other) {
re_free(e0b, e1b) => e0a == e0b && e1a == e1b,
_ => false
}
}
re_scope(e0a) => {
match (*other) {
re_scope(e0b) => e0a == e0b,
_ => false
}
}
re_static => {
match (*other) {
re_static => true,
_ => false
}
}
re_infer(e0a) => {
match (*other) {
re_infer(e0b) => e0a == e0b,
_ => false
}
}
}
}
fn ne(&self, other: &Region) -> bool { !(*self).eq(other) }
}

impl cmp::Eq for bound_region {
fn eq(&self, other: &bound_region) -> bool {
match (*self) {
br_self => {
match (*other) {
br_self => true,
_ => false
}
}
br_anon(e0a) => {
match (*other) {
br_anon(e0b) => e0a == e0b,
_ => false
}
}
br_named(e0a) => {
match (*other) {
br_named(e0b) => e0a == e0b,
_ => false
}
}
br_cap_avoid(e0a, e1a) => {
match (*other) {
br_cap_avoid(e0b, e1b) => e0a == e0b && e1a == e1b,
_ => false
}
}
br_fresh(e0a) => {
match (*other) {
br_fresh(e0b) => e0a == e0b,
_ => false
}
}
}
}
fn ne(&self, other: &bound_region) -> bool { !(*self).eq(other) }
}

impl cmp::Eq for param_bound {
fn eq(&self, other: &param_bound) -> bool {
match (*self) {
bound_copy => {
match (*other) {
bound_copy => true,
_ => false
}
}
bound_durable => {
match (*other) {
bound_durable => true,
_ => false
}
}
bound_owned => {
match (*other) {
bound_owned => true,
_ => false
}
}
bound_const => {
match (*other) {
bound_const => true,
_ => false
}
}
bound_trait(e0a) => {
match (*other) {
bound_trait(e0b) => e0a == e0b,
_ => false
}
}
}
}
fn ne(&self, other: &param_bound) -> bool { !self.eq(other) }
}

// Local Variables:
// mode: rust
// fill-column: 78;
Expand Down

5 comments on commit f02ee42

@bors
Copy link
Contributor

@bors bors commented on f02ee42 Mar 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on f02ee42 Mar 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging apasel422/rust/simplify-impls = f02ee42 into auto

@bors
Copy link
Contributor

@bors bors commented on f02ee42 Mar 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apasel422/rust/simplify-impls = f02ee42 merged ok, testing candidate = 4954d3e

@bors
Copy link
Contributor

@bors bors commented on f02ee42 Mar 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on f02ee42 Mar 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 4954d3e

Please sign in to comment.