]> git.lizzy.rs Git - rust.git/commitdiff
derive Eq and Clone impls where applicable
authorAndrew Paseltiner <apaseltiner@gmail.com>
Tue, 26 Mar 2013 12:04:54 +0000 (08:04 -0400)
committerAndrew Paseltiner <apaseltiner@gmail.com>
Thu, 28 Mar 2013 02:04:23 +0000 (22:04 -0400)
src/librustc/middle/liveness.rs
src/librustc/middle/trans/cabi_x86_64.rs
src/librustc/middle/trans/datum.rs
src/librustc/middle/trans/expr.rs
src/librustc/middle/ty.rs
src/librustc/middle/typeck/infer/region_inference.rs
src/librustdoc/astsrv.rs
src/librustdoc/config.rs
src/libsyntax/attr.rs
src/libsyntax/codemap.rs
src/libsyntax/parse/comments.rs

index 15fc4317bf3a83ca2db32c547456df09eec1ae5c..4d6226a5db6975dde6c0a14aa59880848e7a77ee 100644 (file)
 use middle::moves;
 use util::ppaux::ty_to_str;
 
-use core::cmp;
 use core::hashmap::linear::LinearMap;
 use core::io::WriterUtil;
 use core::io;
 // 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),
@@ -157,38 +149,6 @@ enum LiveNodeKind {
     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 {
index 4d0ad2c19f1159d755732e54b657864124349782..e9769f14b72dadc57412e6bc43c0e001cb77b2c5 100644 (file)
 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,
@@ -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 |
index f81973e169daa20aef10dfffe94b8c79c572eab7..164f6fe44fc6d8680f5c5a827479936bbb8e1526 100644 (file)
 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;
@@ -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,
@@ -158,13 +158,6 @@ fn is_by_value(&self) -> bool {
     }
 }
 
-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)
index 0da1a9acef21225856ae3b63f03fbcf0b9f20f5e..3e1496692ae47692e5f1aee142a9818776e572a3 100644 (file)
 // 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,
@@ -174,18 +175,6 @@ fn to_str(&self, ccx: @CrateContext) -> ~str {
     }
 }
 
-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);
@@ -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,
@@ -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,
index 0d36453c757396551c261b44d8ff985511e77711..088d8183d4818c2c4dee1b07240fe2f5152b4876 100644 (file)
@@ -76,6 +76,7 @@ pub struct method {
     def_id: ast::def_id
 }
 
+#[deriving(Eq)]
 pub struct mt {
     ty: t,
     mutbl: ast::mutability,
@@ -161,22 +162,9 @@ pub enum ast_ty_to_ty_cache_entry {
 
 #[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 {
@@ -417,6 +405,7 @@ fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
 /// 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
@@ -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,
@@ -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,
@@ -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;
index 031363469cd0ac6911660b10de9fac93621cf4f2..24d763eaee13f3090017f6d480485e1e9f234959 100644 (file)
@@ -548,7 +548,6 @@ fn<a,b>(&a, &b, &a) fn<x,y>(&x, &y, &y) fn<a>(&a, &a, &a) fn<a,b,c>(&a,&b,&c)
 use util::ppaux::note_and_explain_region;
 
 use core::cell::{Cell, empty_cell};
-use core::cmp;
 use core::hashmap::linear::{LinearMap, LinearSet};
 use core::result::{Err, Ok, Result};
 use core::to_bytes;
@@ -556,32 +555,13 @@ fn<a,b>(&a, &b, &a) fn<x,y>(&x, &y, &y) fn<a>(&a, &a, &a) fn<a,b,c>(&a,&b,&c)
 use core::vec;
 use syntax::codemap::span;
 
+#[deriving(Eq)]
 enum Constraint {
     ConstrainVarSubVar(RegionVid, RegionVid),
     ConstrainRegSubVar(Region, RegionVid),
     ConstrainVarSubReg(RegionVid, Region)
 }
 
-impl cmp::Eq for Constraint {
-    fn eq(&self, other: &Constraint) -> bool {
-        match ((*self), (*other)) {
-            (ConstrainVarSubVar(v0a, v1a), ConstrainVarSubVar(v0b, v1b)) => {
-                v0a == v0b && v1a == v1b
-            }
-            (ConstrainRegSubVar(ra, va), ConstrainRegSubVar(rb, vb)) => {
-                ra == rb && va == vb
-            }
-            (ConstrainVarSubReg(va, ra), ConstrainVarSubReg(vb, rb)) => {
-                va == vb && ra == rb
-            }
-            (ConstrainVarSubVar(*), _) => false,
-            (ConstrainRegSubVar(*), _) => false,
-            (ConstrainVarSubReg(*), _) => false
-        }
-    }
-    fn ne(&self, other: &Constraint) -> bool { !(*self).eq(other) }
-}
-
 impl to_bytes::IterBytes for Constraint {
    fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
         match *self {
@@ -597,18 +577,12 @@ fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
     }
 }
 
+#[deriving(Eq)]
 struct TwoRegions {
     a: Region,
     b: Region,
 }
 
-impl cmp::Eq for TwoRegions {
-    fn eq(&self, other: &TwoRegions) -> bool {
-        (*self).a == (*other).a && (*self).b == (*other).b
-    }
-    fn ne(&self, other: &TwoRegions) -> bool { !(*self).eq(other) }
-}
-
 impl to_bytes::IterBytes for TwoRegions {
     fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
         to_bytes::iter_bytes_2(&self.a, &self.b, lsb0, f)
index 8f02b789121be221d276f907c576b1bcc0f5a4a7..5bf7e18552ff60f5c0df6874e5ec441ad0eb85ad 100644 (file)
@@ -45,18 +45,11 @@ enum Msg {
     Exit
 }
 
+#[deriving(Clone)]
 pub struct Srv {
     ch: SharedChan<Msg>
 }
 
-impl Clone for Srv {
-    fn clone(&self) -> Srv {
-        Srv {
-            ch: self.ch.clone()
-        }
-    }
-}
-
 pub fn from_str<T>(source: ~str, owner: SrvOwner<T>) -> T {
     run(owner, copy source, parse::from_str_sess)
 }
index 84f2f5191f31a000831391013ac4ddacef20a7f6..2b95d42f40e759d71e1efb60ed2a660f089e6178 100644 (file)
@@ -11,7 +11,6 @@
 use core::prelude::*;
 
 use core::cell::Cell;
-use core::cmp;
 use core::os;
 use core::result;
 use core::run;
@@ -21,6 +20,7 @@
 use std::getopts;
 
 /// The type of document to output
+#[deriving(Eq)]
 pub enum OutputFormat {
     /// Markdown
     pub Markdown,
@@ -28,14 +28,8 @@ pub enum OutputFormat {
     pub PandocHtml
 }
 
-impl cmp::Eq for OutputFormat {
-    fn eq(&self, other: &OutputFormat) -> bool {
-        ((*self) as uint) == ((*other) as uint)
-    }
-    fn ne(&self, other: &OutputFormat) -> bool { !(*self).eq(other) }
-}
-
 /// How to organize the output
+#[deriving(Eq)]
 pub enum OutputStyle {
     /// All in a single document
     pub DocPerCrate,
@@ -43,13 +37,6 @@ pub enum OutputStyle {
     pub DocPerMod
 }
 
-impl cmp::Eq for OutputStyle {
-    fn eq(&self, other: &OutputStyle) -> bool {
-        ((*self) as uint) == ((*other) as uint)
-    }
-    fn ne(&self, other: &OutputStyle) -> bool { !(*self).eq(other) }
-}
-
 /// The configuration for a rustdoc session
 pub struct Config {
     input_crate: Path,
index b22d71afaed2dc72a485df537d2298c9cf58ee06..90e8c0aa6168025d1a1bba9c8ab401f9417cd72f 100644 (file)
@@ -19,7 +19,6 @@
 use diagnostic::span_handler;
 use parse::comments::{doc_comment_style, strip_doc_comment_decoration};
 
-use core::cmp;
 use core::either::Either;
 use core::vec;
 use core::hashmap::linear::LinearSet;
@@ -325,6 +324,7 @@ pub fn foreign_abi(attrs: &[ast::attribute])
     };
 }
 
+#[deriving(Eq)]
 pub enum inline_attr {
     ia_none,
     ia_hint,
@@ -332,13 +332,6 @@ pub enum inline_attr {
     ia_never,
 }
 
-impl cmp::Eq for inline_attr {
-    fn eq(&self, other: &inline_attr) -> bool {
-        ((*self) as uint) == ((*other) as uint)
-    }
-    fn ne(&self, other: &inline_attr) -> bool { !(*self).eq(other) }
-}
-
 /// True if something like #[inline] is found in the list of attrs.
 pub fn find_inline_attr(attrs: &[ast::attribute]) -> inline_attr {
     // FIXME (#2809)---validate the usage of #[inline] and #[inline(always)]
index c082f4c08385038870adbfb1cda01bd4c59173e1..b086670956e243bcbbd5c4575252ed570364182e 100644 (file)
@@ -35,10 +35,12 @@ pub trait Pos {
 }
 
 /// A byte offset
+#[deriving(Eq)]
 pub struct BytePos(uint);
 /// 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(Eq)]
 pub struct CharPos(uint);
 
 // XXX: Lots of boilerplate in these impls, but so far my attempts to fix
@@ -49,11 +51,6 @@ fn from_uint(n: uint) -> BytePos { BytePos(n) }
     fn to_uint(&self) -> uint { **self }
 }
 
-impl cmp::Eq for BytePos {
-    fn eq(&self, other: &BytePos) -> bool { **self == **other }
-    fn ne(&self, other: &BytePos) -> bool { !(*self).eq(other) }
-}
-
 impl cmp::Ord for BytePos {
     fn lt(&self, other: &BytePos) -> bool { **self < **other }
     fn le(&self, other: &BytePos) -> bool { **self <= **other }
@@ -84,11 +81,6 @@ fn from_uint(n: uint) -> CharPos { CharPos(n) }
     fn to_uint(&self) -> uint { **self }
 }
 
-impl cmp::Eq for CharPos {
-    fn eq(&self, other: &CharPos) -> bool { **self == **other }
-    fn ne(&self, other: &CharPos) -> bool { !(*self).eq(other) }
-}
-
 impl cmp::Ord for CharPos {
     fn lt(&self, other: &CharPos) -> bool { **self < **other }
     fn le(&self, other: &CharPos) -> bool { **self <= **other }
index 1b6b25db38ad640248bd049ca8777a5f4bcbfd40..e5685cdb4c7d1a50f497d4f1031065e02446a0ee 100644 (file)
 use parse::token;
 use parse;
 
-use core::cmp;
 use core::io::ReaderUtil;
 use core::io;
 use core::str;
 use core::uint;
 use core::vec;
 
+#[deriving(Eq)]
 pub enum cmnt_style {
     isolated, // No code on either side of each line of the comment
     trailing, // Code exists to the left of the comment
@@ -34,15 +34,6 @@ pub enum cmnt_style {
     blank_line, // Just a manual blank line "\n\n", for layout
 }
 
-impl cmp::Eq for cmnt_style {
-    fn eq(&self, other: &cmnt_style) -> bool {
-        ((*self) as uint) == ((*other) as uint)
-    }
-    fn ne(&self, other: &cmnt_style) -> bool {
-        ((*self) as uint) != ((*other) as uint)
-    }
-}
-
 pub struct cmnt {
     style: cmnt_style,
     lines: ~[~str],