diff options
| -rw-r--r-- | src/libsyntax/ast.rs | 582 | ||||
| -rw-r--r-- | src/libsyntax/codemap.rs | 1 |
2 files changed, 81 insertions, 502 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b26cab7694c..02f7029fac2 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -69,6 +69,7 @@ pub type fn_ident = Option<ident>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct path { span: span, global: bool, @@ -83,23 +84,18 @@ pub type node_id = int; #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct def_id { crate: crate_num, node: node_id, } -pub impl def_id : cmp::Eq { - pure fn eq(&self, other: &def_id) -> bool { - (*self).crate == (*other).crate && (*self).node == (*other).node - } - pure fn ne(&self, other: &def_id) -> bool { !(*self).eq(other) } -} - pub const local_crate: crate_num = 0; pub const crate_node_id: node_id = 0; #[auto_encode] #[auto_decode] +#[deriving_eq] // The AST represents all type param bounds as types. // typeck::collect::compute_bounds matches these against // the "special" built-in traits (see middle::lang_items) and @@ -111,6 +107,7 @@ pub enum ty_param_bound { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct ty_param { ident: ident, id: node_id, @@ -119,6 +116,7 @@ pub struct ty_param { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum def { def_fn(def_id, purity), def_static_method(/* method */ def_id, @@ -147,136 +145,6 @@ pub enum def { def_label(node_id) } -pub impl def : cmp::Eq { - pure fn eq(&self, other: &def) -> bool { - match (*self) { - def_fn(e0a, e1a) => { - match (*other) { - def_fn(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_static_method(e0a, e1a, e2a) => { - match (*other) { - def_static_method(e0b, e1b, e2b) => - e0a == e0b && e1a == e1b && e2a == e2b, - _ => false - } - } - def_self(e0a, e1a) => { - match (*other) { - def_self(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_self_ty(e0a) => { - match (*other) { - def_self_ty(e0b) => e0a == e0b, - _ => false - } - } - def_mod(e0a) => { - match (*other) { - def_mod(e0b) => e0a == e0b, - _ => false - } - } - def_foreign_mod(e0a) => { - match (*other) { - def_foreign_mod(e0b) => e0a == e0b, - _ => false - } - } - def_const(e0a) => { - match (*other) { - def_const(e0b) => e0a == e0b, - _ => false - } - } - def_arg(e0a, e1a, e2a) => { - match (*other) { - def_arg(e0b, e1b, e2b) => - e0a == e0b && e1a == e1b && e2a == e2b, - _ => false - } - } - def_local(e0a, e1a) => { - match (*other) { - def_local(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_variant(e0a, e1a) => { - match (*other) { - def_variant(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_ty(e0a) => { - match (*other) { - def_ty(e0b) => e0a == e0b, - _ => false - } - } - def_prim_ty(e0a) => { - match (*other) { - def_prim_ty(e0b) => e0a == e0b, - _ => false - } - } - def_ty_param(e0a, e1a) => { - match (*other) { - def_ty_param(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_binding(e0a, e1a) => { - match (*other) { - def_binding(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - def_use(e0a) => { - match (*other) { - def_use(e0b) => e0a == e0b, - _ => false - } - } - def_upvar(e0a, e1a, e2a, e3a) => { - match (*other) { - def_upvar(e0b, e1b, e2b, e3b) => - e0a == e0b && e1a == e1b && e2a == e2b && e3a == e3b, - _ => false - } - } - def_struct(e0a) => { - match (*other) { - def_struct(e0b) => e0a == e0b, - _ => false - } - } - def_typaram_binder(e0a) => { - match (*other) { - def_typaram_binder(e1a) => e0a == e1a, - _ => false - } - } - def_region(e0a) => { - match (*other) { - def_region(e0b) => e0a == e0b, - _ => false - } - } - def_label(e0a) => { - match (*other) { - def_label(e0b) => e0a == e0b, - _ => false - } - } - } - } - pure fn ne(&self, other: &def) -> bool { !(*self).eq(other) } -} // The set of meta_items that define the compilation environment of the crate, // used to drive conditional compilation @@ -284,6 +152,7 @@ pub type crate_cfg = ~[@meta_item]; pub type crate = spanned<crate_>; +#[deriving_eq] pub struct crate_ { module: _mod, attrs: ~[attribute], @@ -294,6 +163,7 @@ pub type meta_item = spanned<meta_item_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum meta_item_ { meta_word(~str), meta_list(~str, ~[@meta_item]), @@ -304,6 +174,7 @@ pub type blk = spanned<blk_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct blk_ { view_items: ~[@view_item], stmts: ~[@stmt], @@ -314,6 +185,7 @@ pub struct blk_ { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct pat { id: node_id, node: pat_, @@ -322,6 +194,7 @@ pub struct pat { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct field_pat { ident: ident, pat: @pat, @@ -352,6 +225,7 @@ pub impl binding_mode : to_bytes::IterBytes { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum pat_ { pat_wild, // A pat_ident may either be a new bound variable, @@ -377,6 +251,7 @@ pub enum pat_ { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum mutability { m_mutbl, m_imm, m_const, } pub impl mutability : to_bytes::IterBytes { @@ -385,13 +260,6 @@ pub impl mutability : to_bytes::IterBytes { } } -pub impl mutability : cmp::Eq { - pure fn eq(&self, other: &mutability) -> bool { - ((*self) as uint) == ((*other) as uint) - } - pure fn ne(&self, other: &mutability) -> bool { !(*self).eq(other) } -} - #[auto_encode] #[auto_decode] #[deriving_eq] @@ -440,6 +308,7 @@ pub impl Sigil : ToStr { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum vstore { // FIXME (#3469): Change uint to @expr (actually only constant exprs) vstore_fixed(Option<uint>), // [1,2,3,4] @@ -450,6 +319,7 @@ pub enum vstore { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum expr_vstore { // FIXME (#3469): Change uint to @expr (actually only constant exprs) expr_vstore_fixed(Option<uint>), // [1,2,3,4] @@ -462,6 +332,7 @@ pub enum expr_vstore { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum binop { add, subtract, @@ -483,15 +354,9 @@ pub enum binop { gt, } -pub impl binop : cmp::Eq { - pure fn eq(&self, other: &binop) -> bool { - ((*self) as uint) == ((*other) as uint) - } - pure fn ne(&self, other: &binop) -> bool { !(*self).eq(other) } -} - #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum unop { box(mutability), uniq(mutability), @@ -500,50 +365,11 @@ pub enum unop { neg } -pub impl unop : cmp::Eq { - pure fn eq(&self, other: &unop) -> bool { - match (*self) { - box(e0a) => { - match (*other) { - box(e0b) => e0a == e0b, - _ => false - } - } - uniq(e0a) => { - match (*other) { - uniq(e0b) => e0a == e0b, - _ => false - } - } - deref => { - match (*other) { - deref => true, - _ => false - } - } - not => { - match (*other) { - not => true, - _ => false - } - } - neg => { - match (*other) { - neg => true, - _ => false - } - } - } - } - pure fn ne(&self, other: &unop) -> bool { - !(*self).eq(other) - } -} - // Generally, after typeck you can get the inferred value // using ty::resolved_T(...). #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum inferable<T> { expl(T), infer(node_id) @@ -561,29 +387,10 @@ pub impl<T: to_bytes::IterBytes> inferable<T> : to_bytes::IterBytes { } } -pub impl<T:cmp::Eq> inferable<T> : cmp::Eq { - pure fn eq(&self, other: &inferable<T>) -> bool { - match (*self) { - expl(ref e0a) => { - match (*other) { - expl(ref e0b) => (*e0a) == (*e0b), - _ => false - } - } - infer(e0a) => { - match (*other) { - infer(e0b) => e0a == e0b, - _ => false - } - } - } - } - pure fn ne(&self, other: &inferable<T>) -> bool { !(*self).eq(other) } -} - // "resolved" mode: the real modes. #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum rmode { by_ref, by_val, by_copy } pub impl rmode : to_bytes::IterBytes { @@ -592,14 +399,6 @@ pub impl rmode : to_bytes::IterBytes { } } - -pub impl rmode : cmp::Eq { - pure fn eq(&self, other: &rmode) -> bool { - ((*self) as uint) == ((*other) as uint) - } - pure fn ne(&self, other: &rmode) -> bool { !(*self).eq(other) } -} - // inferable mode. pub type mode = inferable<rmode>; @@ -607,6 +406,7 @@ pub type stmt = spanned<stmt_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum stmt_ { stmt_decl(@decl, node_id), @@ -624,6 +424,7 @@ pub enum stmt_ { // a refinement on pat. #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct local_ { is_mutbl: bool, ty: @Ty, @@ -638,10 +439,12 @@ pub type decl = spanned<decl_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum decl_ { decl_local(~[@local]), decl_item(@item), } #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct arm { pats: ~[@pat], guard: Option<@expr>, @@ -650,6 +453,7 @@ pub struct arm { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct field_ { mutbl: mutability, ident: ident, @@ -660,22 +464,12 @@ pub type field = spanned<field_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum blk_check_mode { default_blk, unsafe_blk, } -pub impl blk_check_mode : cmp::Eq { - pure fn eq(&self, other: &blk_check_mode) -> bool { - match ((*self), (*other)) { - (default_blk, default_blk) => true, - (unsafe_blk, unsafe_blk) => true, - (default_blk, _) => false, - (unsafe_blk, _) => false, - } - } - pure fn ne(&self, other: &blk_check_mode) -> bool { !(*self).eq(other) } -} - #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct expr { id: node_id, // Extra node ID is only used for index, assign_op, unary, binary, method @@ -687,6 +481,7 @@ pub struct expr { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum log_level { error, debug, log_other } // 0 = error, 1 = debug, 2 = log_other @@ -701,6 +496,7 @@ pub enum CallSugar { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum expr_ { expr_vstore(@expr, expr_vstore), expr_vec(~[@expr], mutability), @@ -777,6 +573,7 @@ pub enum expr_ { // #[auto_encode] #[auto_decode] +#[deriving_eq] #[doc="For macro invocations; parsing is delegated to the macro"] pub enum token_tree { // a single token @@ -851,6 +648,7 @@ pub type matcher = spanned<matcher_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum matcher_ { // match one token match_tok(::parse::token::Token), @@ -865,6 +663,7 @@ pub type mac = spanned<mac_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum mac_ { mac_invoc_tt(@path,~[token_tree]), // new macro-invocation } @@ -873,6 +672,7 @@ pub type lit = spanned<lit_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum lit_ { lit_str(@~str), lit_int(i64, int_ty), @@ -884,40 +684,11 @@ pub enum lit_ { lit_bool(bool), } -pub impl lit_: cmp::Eq { - pure fn eq(&self, other: &lit_) -> bool { - match ((*self), *other) { - (lit_str(a), lit_str(b)) => a == b, - (lit_int(val_a, ty_a), lit_int(val_b, ty_b)) => { - val_a == val_b && ty_a == ty_b - } - (lit_uint(val_a, ty_a), lit_uint(val_b, ty_b)) => { - val_a == val_b && ty_a == ty_b - } - (lit_int_unsuffixed(a), lit_int_unsuffixed(b)) => a == b, - (lit_float(val_a, ty_a), lit_float(val_b, ty_b)) => { - val_a == val_b && ty_a == ty_b - } - (lit_float_unsuffixed(a), lit_float_unsuffixed(b)) => a == b, - (lit_nil, lit_nil) => true, - (lit_bool(a), lit_bool(b)) => a == b, - (lit_str(_), _) => false, - (lit_int(*), _) => false, - (lit_uint(*), _) => false, - (lit_int_unsuffixed(*), _) => false, - (lit_float(*), _) => false, - (lit_float_unsuffixed(*), _) => false, - (lit_nil, _) => false, - (lit_bool(_), _) => false - } - } - pure fn ne(&self, other: &lit_) -> bool { !(*self).eq(other) } -} - // NB: If you change this, you'll probably want to change the corresponding // type structure in middle/ty.rs as well. #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct mt { ty: @Ty, mutbl: mutability, @@ -925,6 +696,7 @@ pub struct mt { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct ty_field_ { ident: ident, mt: mt, @@ -934,6 +706,7 @@ pub type ty_field = spanned<ty_field_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct ty_method { ident: ident, attrs: ~[attribute], @@ -947,6 +720,7 @@ pub struct ty_method { #[auto_encode] #[auto_decode] +#[deriving_eq] // A trait method is either required (meaning it doesn't have an // implementation, just a signature) or provided (meaning it has a default // implementation). @@ -957,6 +731,7 @@ pub enum trait_method { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, } pub impl int_ty : ToStr { @@ -971,28 +746,9 @@ pub impl int_ty : to_bytes::IterBytes { } } -pub impl int_ty : cmp::Eq { - pure fn eq(&self, other: &int_ty) -> bool { - match ((*self), (*other)) { - (ty_i, ty_i) => true, - (ty_char, ty_char) => true, - (ty_i8, ty_i8) => true, - (ty_i16, ty_i16) => true, - (ty_i32, ty_i32) => true, - (ty_i64, ty_i64) => true, - (ty_i, _) => false, - (ty_char, _) => false, - (ty_i8, _) => false, - (ty_i16, _) => false, - (ty_i32, _) => false, - (ty_i64, _) => false, - } - } - pure fn ne(&self, other: &int_ty) -> bool { !(*self).eq(other) } -} - #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, } pub impl uint_ty : ToStr { @@ -1007,26 +763,9 @@ pub impl uint_ty : to_bytes::IterBytes { } } -pub impl uint_ty : cmp::Eq { - pure fn eq(&self, other: &uint_ty) -> bool { - match ((*self), (*other)) { - (ty_u, ty_u) => true, - (ty_u8, ty_u8) => true, - (ty_u16, ty_u16) => true, - (ty_u32, ty_u32) => true, - (ty_u64, ty_u64) => true, - (ty_u, _) => false, - (ty_u8, _) => false, - (ty_u16, _) => false, - (ty_u32, _) => false, - (ty_u64, _) => false - } - } - pure fn ne(&self, other: &uint_ty) -> bool { !(*self).eq(other) } -} - #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum float_ty { ty_f, ty_f32, ty_f64, } pub impl float_ty : ToStr { @@ -1041,16 +780,7 @@ pub impl float_ty : to_bytes::IterBytes { } } -pub impl float_ty : cmp::Eq { - pure fn eq(&self, other: &float_ty) -> bool { - match ((*self), (*other)) { - (ty_f, ty_f) | (ty_f32, ty_f32) | (ty_f64, ty_f64) => true, - (ty_f, _) | (ty_f32, _) | (ty_f64, _) => false - } - } - pure fn ne(&self, other: &float_ty) -> bool { !(*self).eq(other) } -} - +// NB Eq method appears below. #[auto_encode] #[auto_decode] pub struct Ty { @@ -1062,6 +792,7 @@ pub struct Ty { // Not represented directly in the AST, referred to by name through a ty_path. #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum prim_ty { ty_int(int_ty), ty_uint(uint_ty), @@ -1070,46 +801,9 @@ pub enum prim_ty { ty_bool, } -pub impl prim_ty : cmp::Eq { - pure fn eq(&self, other: &prim_ty) -> bool { - match (*self) { - ty_int(e0a) => { - match (*other) { - ty_int(e0b) => e0a == e0b, - _ => false - } - } - ty_uint(e0a) => { - match (*other) { - ty_uint(e0b) => e0a == e0b, - _ => false - } - } - ty_float(e0a) => { - match (*other) { - ty_float(e0b) => e0a == e0b, - _ => false - } - } - ty_str => { - match (*other) { - ty_str => true, - _ => false - } - } - ty_bool => { - match (*other) { - ty_bool => true, - _ => false - } - } - } - } - pure fn ne(&self, other: &prim_ty) -> bool { !(*self).eq(other) } -} - #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct region { id: node_id, node: region_, @@ -1117,6 +811,7 @@ pub struct region { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum region_ { re_anon, re_static, @@ -1149,6 +844,7 @@ pub impl Onceness : to_bytes::IterBytes { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct TyClosure { sigil: Sigil, region: Option<@region>, @@ -1167,6 +863,7 @@ pub struct TyBareFn { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum ty_ { ty_nil, ty_bot, /* bottom type */ @@ -1207,6 +904,7 @@ pub impl Ty : to_bytes::IterBytes { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct arg { mode: mode, is_mutbl: bool, @@ -1217,6 +915,7 @@ pub struct arg { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct fn_decl { inputs: ~[arg], output: @Ty, @@ -1225,6 +924,7 @@ pub struct fn_decl { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum purity { pure_fn, // declared with "pure fn" unsafe_fn, // declared with "unsafe fn" @@ -1249,15 +949,9 @@ pub impl purity : to_bytes::IterBytes { } } -pub impl purity : cmp::Eq { - pure fn eq(&self, other: &purity) -> bool { - ((*self) as uint) == ((*other) as uint) - } - pure fn ne(&self, other: &purity) -> bool { !(*self).eq(other) } -} - #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum ret_style { noreturn, // functions with return type _|_ that always // raise an error or exit (i.e. never return to the caller) @@ -1270,20 +964,9 @@ pub impl ret_style : to_bytes::IterBytes { } } -pub impl ret_style : cmp::Eq { - pure fn eq(&self, other: &ret_style) -> bool { - match ((*self), (*other)) { - (noreturn, noreturn) => true, - (return_val, return_val) => true, - (noreturn, _) => false, - (return_val, _) => false, - } - } - pure fn ne(&self, other: &ret_style) -> bool { !(*self).eq(other) } -} - #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum self_ty_ { sty_static, // no self: static method sty_by_ref, // old by-reference self: `` @@ -1293,54 +976,11 @@ pub enum self_ty_ { sty_uniq(mutability) // by-unique-pointer self: `~self` } -pub impl self_ty_ : cmp::Eq { - pure fn eq(&self, other: &self_ty_) -> bool { - match (*self) { - sty_static => { - match (*other) { - sty_static => true, - _ => false - } - } - sty_by_ref => { - match (*other) { - sty_by_ref => true, - _ => false - } - } - sty_value => { - match (*other) { - sty_value => true, - _ => false - } - } - sty_region(e0a) => { - match (*other) { - sty_region(e0b) => e0a == e0b, - _ => false - } - } - sty_box(e0a) => { - match (*other) { - sty_box(e0b) => e0a == e0b, - _ => false - } - } - sty_uniq(e0a) => { - match (*other) { - sty_uniq(e0b) => e0a == e0b, - _ => false - } - } - } - } - pure fn ne(&self, other: &self_ty_) -> bool { !(*self).eq(other) } -} - pub type self_ty = spanned<self_ty_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct method { ident: ident, attrs: ~[attribute], @@ -1357,6 +997,7 @@ pub struct method { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct _mod { view_items: ~[@view_item], items: ~[@item], @@ -1364,6 +1005,7 @@ pub struct _mod { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum foreign_abi { foreign_abi_rust_intrinsic, foreign_abi_cdecl, @@ -1373,31 +1015,12 @@ pub enum foreign_abi { // Foreign mods can be named or anonymous #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum foreign_mod_sort { named, anonymous } -pub impl foreign_mod_sort : cmp::Eq { - pure fn eq(&self, other: &foreign_mod_sort) -> bool { - ((*self) as uint) == ((*other) as uint) - } - pure fn ne(&self, other: &foreign_mod_sort) -> bool { !(*self).eq(other) } -} - -pub impl foreign_abi : cmp::Eq { - pure fn eq(&self, other: &foreign_abi) -> bool { - match ((*self), (*other)) { - (foreign_abi_rust_intrinsic, foreign_abi_rust_intrinsic) => true, - (foreign_abi_cdecl, foreign_abi_cdecl) => true, - (foreign_abi_stdcall, foreign_abi_stdcall) => true, - (foreign_abi_rust_intrinsic, _) => false, - (foreign_abi_cdecl, _) => false, - (foreign_abi_stdcall, _) => false, - } - } - pure fn ne(&self, other: &foreign_abi) -> bool { !(*self).eq(other) } -} - #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct foreign_mod { sort: foreign_mod_sort, abi: ident, @@ -1407,6 +1030,7 @@ pub struct foreign_mod { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct variant_arg { ty: @Ty, id: node_id, @@ -1414,6 +1038,7 @@ pub struct variant_arg { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum variant_kind { tuple_variant_kind(~[variant_arg]), struct_variant_kind(@struct_def), @@ -1422,6 +1047,7 @@ pub enum variant_kind { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct enum_def_ { variants: ~[variant], common: Option<@struct_def>, @@ -1429,10 +1055,12 @@ pub struct enum_def_ { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum enum_def = enum_def_; #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct variant_ { name: ident, attrs: ~[attribute], @@ -1446,6 +1074,7 @@ pub type variant = spanned<variant_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct path_list_ident_ { name: ident, id: node_id, @@ -1455,19 +1084,14 @@ pub type path_list_ident = spanned<path_list_ident_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum namespace { module_ns, type_value_ns } -pub impl namespace : cmp::Eq { - pure fn eq(&self, other: &namespace) -> bool { - ((*self) as uint) == ((*other) as uint) - } - pure fn ne(&self, other: &namespace) -> bool { !(*self).eq(other) } -} - pub type view_path = spanned<view_path_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum view_path_ { // quux = foo::bar::baz @@ -1486,6 +1110,7 @@ pub enum view_path_ { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct view_item { node: view_item_, attrs: ~[attribute], @@ -1495,6 +1120,7 @@ pub struct view_item { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum view_item_ { view_item_use(ident, ~[@meta_item], node_id), view_item_import(~[@view_path]), @@ -1508,18 +1134,13 @@ pub type attribute = spanned<attribute_>; // distinguished for pretty-printing. #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum attr_style { attr_outer, attr_inner, } -pub impl attr_style : cmp::Eq { - pure fn eq(&self, other: &attr_style) -> bool { - ((*self) as uint) == ((*other) as uint) - } - pure fn ne(&self, other: &attr_style) -> bool { !(*self).eq(other) } -} - // doc-comments are promoted to attributes that have is_sugared_doc = true #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct attribute_ { style: attr_style, value: meta_item, @@ -1535,6 +1156,7 @@ pub struct attribute_ { */ #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct trait_ref { path: @path, ref_id: node_id, @@ -1542,24 +1164,12 @@ pub struct trait_ref { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum visibility { public, private, inherited } -pub impl visibility : cmp::Eq { - pure fn eq(&self, other: &visibility) -> bool { - match ((*self), (*other)) { - (public, public) => true, - (private, private) => true, - (inherited, inherited) => true, - (public, _) => false, - (private, _) => false, - (inherited, _) => false, - } - } - pure fn ne(&self, other: &visibility) -> bool { !(*self).eq(other) } -} - #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct struct_field_ { kind: struct_field_kind, id: node_id, @@ -1570,40 +1180,15 @@ pub type struct_field = spanned<struct_field_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum struct_field_kind { named_field(ident, struct_mutability, visibility), unnamed_field // element of a tuple-like struct } -pub impl struct_field_kind : cmp::Eq { - pure fn eq(&self, other: &struct_field_kind) -> bool { - match (*self) { - named_field(ident_a, struct_mutability_a, visibility_a) => { - match *other { - named_field(ident_b, struct_mutability_b, visibility_b) - => { - ident_a == ident_b && - struct_mutability_a == struct_mutability_b && - visibility_a == visibility_b - } - unnamed_field => false - } - } - unnamed_field => { - match *other { - named_field(*) => false, - unnamed_field => true - } - } - } - } - pure fn ne(&self, other: &struct_field_kind) -> bool { - !(*self).eq(other) - } -} - #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct struct_def { fields: ~[@struct_field], /* fields */ /* (not including ctor or dtor) */ @@ -1620,6 +1205,7 @@ pub struct struct_def { */ #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct item { ident: ident, attrs: ~[attribute], @@ -1631,6 +1217,7 @@ pub struct item { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum item_ { item_const(@Ty, @expr), item_fn(fn_decl, purity, ~[ty_param], blk), @@ -1641,14 +1228,15 @@ pub enum item_ { item_struct(@struct_def, ~[ty_param]), item_trait(~[ty_param], ~[@trait_ref], ~[trait_method]), item_impl(~[ty_param], - Option<@trait_ref>, /* (optional) trait this impl implements */ - @Ty, /* self */ + Option<@trait_ref>, // (optional) trait this impl implements + @Ty, // self ~[@method]), item_mac(mac), } #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum struct_mutability { struct_mutable, struct_immutable } pub impl struct_mutability : to_bytes::IterBytes { @@ -1657,24 +1245,11 @@ pub impl struct_mutability : to_bytes::IterBytes { } } -pub impl struct_mutability : cmp::Eq { - pure fn eq(&self, other: &struct_mutability) -> bool { - match ((*self), (*other)) { - (struct_mutable, struct_mutable) => true, - (struct_immutable, struct_immutable) => true, - (struct_mutable, _) => false, - (struct_immutable, _) => false, - } - } - pure fn ne(&self, other: &struct_mutability) -> bool { - !(*self).eq(other) - } -} - pub type struct_dtor = spanned<struct_dtor_>; #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct struct_dtor_ { id: node_id, attrs: ~[attribute], @@ -1684,6 +1259,7 @@ pub struct struct_dtor_ { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct foreign_item { ident: ident, attrs: ~[attribute], @@ -1695,6 +1271,7 @@ pub struct foreign_item { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum foreign_item_ { foreign_item_fn(fn_decl, purity, ~[ty_param]), foreign_item_const(@Ty) @@ -1705,6 +1282,7 @@ pub enum foreign_item_ { // that we trans. #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum inlined_item { ii_item(@item), ii_method(def_id /* impl id */, @method), diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index a509325face..3fbf732c143 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -130,6 +130,7 @@ pub struct span { #[auto_encode] #[auto_decode] +#[deriving_eq] pub struct spanned<T> { node: T, span: span } pub impl span : cmp::Eq { |
