Skip to content

Commit 4954d3e

Browse files
committed
auto merge of #5575 : apasel422/rust/simplify-impls, r=thestinger
2 parents 8896336 + f02ee42 commit 4954d3e

File tree

11 files changed

+21
-303
lines changed

11 files changed

+21
-303
lines changed

src/librustc/middle/liveness.rs

+3-43
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ use middle::typeck;
111111
use middle::moves;
112112
use util::ppaux::ty_to_str;
113113

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

139+
#[deriving(Eq)]
140140
struct Variable(uint);
141+
#[deriving(Eq)]
141142
struct LiveNode(uint);
142143

143-
impl cmp::Eq for Variable {
144-
fn eq(&self, other: &Variable) -> bool { *(*self) == *(*other) }
145-
fn ne(&self, other: &Variable) -> bool { *(*self) != *(*other) }
146-
}
147-
148-
impl cmp::Eq for LiveNode {
149-
fn eq(&self, other: &LiveNode) -> bool { *(*self) == *(*other) }
150-
fn ne(&self, other: &LiveNode) -> bool { *(*self) != *(*other) }
151-
}
152-
144+
#[deriving(Eq)]
153145
enum LiveNodeKind {
154146
FreeVarNode(span),
155147
ExprNode(span),
156148
VarDefNode(span),
157149
ExitNode
158150
}
159151

160-
impl cmp::Eq for LiveNodeKind {
161-
fn eq(&self, other: &LiveNodeKind) -> bool {
162-
match (*self) {
163-
FreeVarNode(e0a) => {
164-
match (*other) {
165-
FreeVarNode(e0b) => e0a == e0b,
166-
_ => false
167-
}
168-
}
169-
ExprNode(e0a) => {
170-
match (*other) {
171-
ExprNode(e0b) => e0a == e0b,
172-
_ => false
173-
}
174-
}
175-
VarDefNode(e0a) => {
176-
match (*other) {
177-
VarDefNode(e0b) => e0a == e0b,
178-
_ => false
179-
}
180-
}
181-
ExitNode => {
182-
match (*other) {
183-
ExitNode => true,
184-
_ => false
185-
}
186-
}
187-
}
188-
}
189-
fn ne(&self, other: &LiveNodeKind) -> bool { !(*self).eq(other) }
190-
}
191-
192152
fn live_node_kind_to_str(lnk: LiveNodeKind, cx: ty::ctxt) -> ~str {
193153
let cm = cx.sess.codemap;
194154
match lnk {

src/librustc/middle/trans/cabi_x86_64.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ use lib::llvm::struct_tys;
1818
use middle::trans::common::*;
1919
use middle::trans::cabi::*;
2020

21-
use core::cmp;
2221
use core::libc::c_uint;
2322
use core::option;
2423
use core::option::Option;
2524
use core::uint;
2625
use core::vec;
2726

27+
#[deriving(Eq)]
2828
enum x86_64_reg_class {
2929
no_class,
3030
integer_class,
@@ -40,13 +40,6 @@ enum x86_64_reg_class {
4040
memory_class
4141
}
4242

43-
impl cmp::Eq for x86_64_reg_class {
44-
fn eq(&self, other: &x86_64_reg_class) -> bool {
45-
((*self) as uint) == ((*other) as uint)
46-
}
47-
fn ne(&self, other: &x86_64_reg_class) -> bool { !(*self).eq(other) }
48-
}
49-
5043
fn is_sse(++c: x86_64_reg_class) -> bool {
5144
return match c {
5245
sse_fs_class | sse_fv_class |

src/librustc/middle/trans/datum.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ use middle::ty;
104104
use util::common::indenter;
105105
use util::ppaux::ty_to_str;
106106

107-
use core::cmp;
108107
use core::container::Set; // XXX: this should not be necessary
109108
use core::to_bytes;
110109
use core::uint;
@@ -140,6 +139,7 @@ pub struct DatumBlock {
140139
datum: Datum,
141140
}
142141

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

161-
impl cmp::Eq for DatumMode {
162-
fn eq(&self, other: &DatumMode) -> bool {
163-
(*self) as uint == (*other as uint)
164-
}
165-
fn ne(&self, other: &DatumMode) -> bool { !(*self).eq(other) }
166-
}
167-
168161
impl to_bytes::IterBytes for DatumMode {
169162
fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
170163
(*self as uint).iter_bytes(lsb0, f)

src/librustc/middle/trans/expr.rs

+2-30
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ use syntax::codemap;
160160
// These are passed around by the code generating functions to track the
161161
// destination of a computation's value.
162162

163+
#[deriving(Eq)]
163164
pub enum Dest {
164165
SaveIn(ValueRef),
165166
Ignore,
@@ -174,18 +175,6 @@ pub impl Dest {
174175
}
175176
}
176177

177-
impl cmp::Eq for Dest {
178-
fn eq(&self, other: &Dest) -> bool {
179-
match ((*self), (*other)) {
180-
(SaveIn(e0a), SaveIn(e0b)) => e0a == e0b,
181-
(Ignore, Ignore) => true,
182-
(SaveIn(*), _) => false,
183-
(Ignore, _) => false,
184-
}
185-
}
186-
fn ne(&self, other: &Dest) -> bool { !(*self).eq(other) }
187-
}
188-
189178
fn drop_and_cancel_clean(bcx: block, dat: Datum) -> block {
190179
let bcx = dat.drop_val(bcx);
191180
dat.cancel_clean(bcx);
@@ -1682,6 +1671,7 @@ fn float_cast(bcx: block, lldsttype: TypeRef, llsrctype: TypeRef,
16821671
} else { llsrc };
16831672
}
16841673
1674+
#[deriving(Eq)]
16851675
pub enum cast_kind {
16861676
cast_pointer,
16871677
cast_integral,
@@ -1690,24 +1680,6 @@ pub enum cast_kind {
16901680
cast_other,
16911681
}
16921682
1693-
impl cmp::Eq for cast_kind {
1694-
fn eq(&self, other: &cast_kind) -> bool {
1695-
match ((*self), (*other)) {
1696-
(cast_pointer, cast_pointer) => true,
1697-
(cast_integral, cast_integral) => true,
1698-
(cast_float, cast_float) => true,
1699-
(cast_enum, cast_enum) => true,
1700-
(cast_other, cast_other) => true,
1701-
(cast_pointer, _) => false,
1702-
(cast_integral, _) => false,
1703-
(cast_float, _) => false,
1704-
(cast_enum, _) => false,
1705-
(cast_other, _) => false,
1706-
}
1707-
}
1708-
fn ne(&self, other: &cast_kind) -> bool { !(*self).eq(other) }
1709-
}
1710-
17111683
pub fn cast_type_kind(t: ty::t) -> cast_kind {
17121684
match ty::get(t).sty {
17131685
ty::ty_float(*) => cast_float,

src/librustc/middle/ty.rs

+5-135
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub struct method {
7676
def_id: ast::def_id
7777
}
7878

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

162163
#[auto_encode]
163164
#[auto_decode]
165+
#[deriving(Eq)]
164166
pub enum region_variance { rv_covariant, rv_invariant, rv_contravariant }
165167

166-
impl cmp::Eq for region_variance {
167-
fn eq(&self, other: &region_variance) -> bool {
168-
match ((*self), (*other)) {
169-
(rv_covariant, rv_covariant) => true,
170-
(rv_invariant, rv_invariant) => true,
171-
(rv_contravariant, rv_contravariant) => true,
172-
(rv_covariant, _) => false,
173-
(rv_invariant, _) => false,
174-
(rv_contravariant, _) => false
175-
}
176-
}
177-
fn ne(&self, other: &region_variance) -> bool { !(*self).eq(other) }
178-
}
179-
180168
#[auto_encode]
181169
#[auto_decode]
182170
pub enum AutoAdjustment {
@@ -417,6 +405,7 @@ impl to_bytes::IterBytes for param_ty {
417405
/// Representation of regions:
418406
#[auto_encode]
419407
#[auto_decode]
408+
#[deriving(Eq)]
420409
pub enum Region {
421410
/// Bound regions are found (primarily) in function types. They indicate
422411
/// region parameters that have yet to be replaced with actual regions
@@ -446,6 +435,7 @@ pub enum Region {
446435

447436
#[auto_encode]
448437
#[auto_decode]
438+
#[deriving(Eq)]
449439
pub enum bound_region {
450440
/// The self region for structs, impls (&T in a type defn or &'self T)
451441
br_self,
@@ -585,6 +575,7 @@ pub enum type_err {
585575
terr_float_mismatch(expected_found<ast::float_ty>)
586576
}
587577

578+
#[deriving(Eq)]
588579
pub enum param_bound {
589580
bound_copy,
590581
bound_durable,
@@ -4367,127 +4358,6 @@ pub fn get_impl_id(tcx: ctxt, trait_id: def_id, self_ty: t) -> def_id {
43674358
}
43684359
}
43694360

4370-
impl cmp::Eq for mt {
4371-
fn eq(&self, other: &mt) -> bool {
4372-
(*self).ty == (*other).ty && (*self).mutbl == (*other).mutbl
4373-
}
4374-
fn ne(&self, other: &mt) -> bool { !(*self).eq(other) }
4375-
}
4376-
4377-
impl cmp::Eq for Region {
4378-
fn eq(&self, other: &Region) -> bool {
4379-
match (*self) {
4380-
re_bound(e0a) => {
4381-
match (*other) {
4382-
re_bound(e0b) => e0a == e0b,
4383-
_ => false
4384-
}
4385-
}
4386-
re_free(e0a, e1a) => {
4387-
match (*other) {
4388-
re_free(e0b, e1b) => e0a == e0b && e1a == e1b,
4389-
_ => false
4390-
}
4391-
}
4392-
re_scope(e0a) => {
4393-
match (*other) {
4394-
re_scope(e0b) => e0a == e0b,
4395-
_ => false
4396-
}
4397-
}
4398-
re_static => {
4399-
match (*other) {
4400-
re_static => true,
4401-
_ => false
4402-
}
4403-
}
4404-
re_infer(e0a) => {
4405-
match (*other) {
4406-
re_infer(e0b) => e0a == e0b,
4407-
_ => false
4408-
}
4409-
}
4410-
}
4411-
}
4412-
fn ne(&self, other: &Region) -> bool { !(*self).eq(other) }
4413-
}
4414-
4415-
impl cmp::Eq for bound_region {
4416-
fn eq(&self, other: &bound_region) -> bool {
4417-
match (*self) {
4418-
br_self => {
4419-
match (*other) {
4420-
br_self => true,
4421-
_ => false
4422-
}
4423-
}
4424-
br_anon(e0a) => {
4425-
match (*other) {
4426-
br_anon(e0b) => e0a == e0b,
4427-
_ => false
4428-
}
4429-
}
4430-
br_named(e0a) => {
4431-
match (*other) {
4432-
br_named(e0b) => e0a == e0b,
4433-
_ => false
4434-
}
4435-
}
4436-
br_cap_avoid(e0a, e1a) => {
4437-
match (*other) {
4438-
br_cap_avoid(e0b, e1b) => e0a == e0b && e1a == e1b,
4439-
_ => false
4440-
}
4441-
}
4442-
br_fresh(e0a) => {
4443-
match (*other) {
4444-
br_fresh(e0b) => e0a == e0b,
4445-
_ => false
4446-
}
4447-
}
4448-
}
4449-
}
4450-
fn ne(&self, other: &bound_region) -> bool { !(*self).eq(other) }
4451-
}
4452-
4453-
impl cmp::Eq for param_bound {
4454-
fn eq(&self, other: &param_bound) -> bool {
4455-
match (*self) {
4456-
bound_copy => {
4457-
match (*other) {
4458-
bound_copy => true,
4459-
_ => false
4460-
}
4461-
}
4462-
bound_durable => {
4463-
match (*other) {
4464-
bound_durable => true,
4465-
_ => false
4466-
}
4467-
}
4468-
bound_owned => {
4469-
match (*other) {
4470-
bound_owned => true,
4471-
_ => false
4472-
}
4473-
}
4474-
bound_const => {
4475-
match (*other) {
4476-
bound_const => true,
4477-
_ => false
4478-
}
4479-
}
4480-
bound_trait(e0a) => {
4481-
match (*other) {
4482-
bound_trait(e0b) => e0a == e0b,
4483-
_ => false
4484-
}
4485-
}
4486-
}
4487-
}
4488-
fn ne(&self, other: &param_bound) -> bool { !self.eq(other) }
4489-
}
4490-
44914361
// Local Variables:
44924362
// mode: rust
44934363
// fill-column: 78;

0 commit comments

Comments
 (0)