derive Eq and Clone impls where applicable

This commit is contained in:
Andrew Paseltiner 2013-03-26 08:04:54 -04:00
parent f7f6013a62
commit f02ee42a86
11 changed files with 21 additions and 303 deletions

View file

@ -111,7 +111,6 @@
use middle::moves;
use util::ppaux::ty_to_str;
use core::cmp;
use core::hashmap::linear::LinearMap;
use core::io::WriterUtil;
use core::io;
@ -137,19 +136,12 @@
// 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 {

View file

@ -18,13 +18,13 @@
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 |

View file

@ -104,7 +104,6 @@
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)

View file

@ -160,6 +160,7 @@
// 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,

View 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;

View 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)

View 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)
}

View 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,

View 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)]

View 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 }

View file

@ -20,13 +20,13 @@
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],