From 3829ac2a52f12b08501cb25d82de32f39fbe801e Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 22 Mar 2014 16:30:45 -0400 Subject: [PATCH] use TotalEq for HashMap Closes #5283 --- src/libcollections/enum_set.rs | 2 +- src/libcollections/hashmap.rs | 57 +++---- src/libcollections/lru_cache.rs | 10 +- src/librustc/middle/borrowck/mod.rs | 6 +- src/librustc/middle/mem_categorization.rs | 10 +- src/librustc/middle/resolve.rs | 2 +- src/librustc/middle/trans/common.rs | 6 +- src/librustc/middle/trans/datum.rs | 2 +- src/librustc/middle/ty.rs | 54 +++--- .../typeck/infer/region_inference/mod.rs | 4 +- src/librustc/middle/typeck/mod.rs | 2 +- src/librustc/util/nodemap.rs | 2 +- src/libserialize/collection_impls.rs | 8 +- src/libstd/fmt/parse.rs | 4 +- src/libstd/path/posix.rs | 4 +- src/libstd/path/windows.rs | 4 +- src/libstd/ptr.rs | 8 +- src/libstd/rc.rs | 9 +- src/libsyntax/abi.rs | 4 +- src/libsyntax/ast.rs | 156 +++++++++--------- src/libsyntax/codemap.rs | 9 +- src/libsyntax/owned_slice.rs | 2 + src/libsyntax/parse/obsolete.rs | 2 +- src/libsyntax/parse/token.rs | 6 +- src/libsyntax/util/interner.rs | 2 +- src/libtest/stats.rs | 2 +- src/test/run-pass/issue-12860.rs | 2 +- src/test/run-pass/regions-mock-tcx.rs | 4 +- 28 files changed, 203 insertions(+), 180 deletions(-) diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index 7fda99d8d2c..07f3181d218 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -15,7 +15,7 @@ use std::num::Bitwise; -#[deriving(Clone, Eq, Hash, Show)] +#[deriving(Clone, Eq, TotalEq, Hash, Show)] /// A specialized Set implementation to use enum types. pub struct EnumSet { // We must maintain the invariant that no bits are set diff --git a/src/libcollections/hashmap.rs b/src/libcollections/hashmap.rs index a1f815df72e..5ec5db45f27 100644 --- a/src/libcollections/hashmap.rs +++ b/src/libcollections/hashmap.rs @@ -12,7 +12,7 @@ use std::container::{Container, Mutable, Map, MutableMap, Set, MutableSet}; use std::clone::Clone; -use std::cmp::{Eq, Equiv, max}; +use std::cmp::{Eq, TotalEq, Equiv, max}; use std::default::Default; use std::fmt; use std::fmt::Show; @@ -140,6 +140,7 @@ mod table { } /// A hash that is not zero, since we use that to represent empty buckets. + #[deriving(Eq)] pub struct SafeHash { priv hash: u64, } @@ -149,10 +150,6 @@ mod table { pub fn inspect(&self) -> u64 { self.hash } } - impl Eq for SafeHash { - fn eq(&self, other: &SafeHash) -> bool { self.hash == other.hash } - } - /// We need to remove hashes of 0. That's reserved for empty buckets. /// This function wraps up `hash_keyed` to be the only way outside this /// module to generate a SafeHash. @@ -698,7 +695,7 @@ fn grow_at(capacity: uint, load_factor: Fraction) -> uint { fraction_mul(capacity, load_factor) } -impl, V, S, H: Hasher> HashMap { +impl, V, S, H: Hasher> HashMap { /// Get the number of elements which will force the capacity to shrink. /// When size == self.shrink_at(), we halve the capacity. fn shrink_at(&self) -> uint { @@ -799,12 +796,12 @@ impl, V, S, H: Hasher> HashMap { } } -impl, V, S, H: Hasher> Container for HashMap { +impl, V, S, H: Hasher> Container for HashMap { /// Return the number of elements in the map fn len(&self) -> uint { self.table.size() } } -impl, V, S, H: Hasher> Mutable for HashMap { +impl, V, S, H: Hasher> Mutable for HashMap { /// Clear the map, removing all key-value pairs. fn clear(&mut self) { self.minimum_capacity = self.table.size(); @@ -819,7 +816,7 @@ impl, V, S, H: Hasher> Mutable for HashMap { } -impl, V, S, H: Hasher> Map for HashMap { +impl, V, S, H: Hasher> Map for HashMap { fn find<'a>(&'a self, k: &K) -> Option<&'a V> { self.search(k).map(|idx| { let (_, v) = self.table.read(&idx); @@ -832,7 +829,7 @@ impl, V, S, H: Hasher> Map for HashMap { } } -impl, V, S, H: Hasher> MutableMap for HashMap { +impl, V, S, H: Hasher> MutableMap for HashMap { fn find_mut<'a>(&'a mut self, k: &K) -> Option<&'a mut V> { match self.search(k) { None => None, @@ -969,7 +966,7 @@ impl, V, S, H: Hasher> MutableMap for HashMap } } -impl HashMap { +impl HashMap { /// Create an empty HashMap. pub fn new() -> HashMap { HashMap::with_capacity(INITIAL_CAPACITY) @@ -984,7 +981,7 @@ impl HashMap { } } -impl, V, S, H: Hasher> HashMap { +impl, V, S, H: Hasher> HashMap { pub fn with_hasher(hasher: H) -> HashMap { HashMap::with_capacity_and_hasher(INITIAL_CAPACITY, hasher) } @@ -1296,7 +1293,7 @@ impl, V, S, H: Hasher> HashMap { } } -impl, V: Clone, S, H: Hasher> HashMap { +impl, V: Clone, S, H: Hasher> HashMap { /// Like `find`, but returns a copy of the value. pub fn find_copy(&self, k: &K) -> Option { self.find(k).map(|v| (*v).clone()) @@ -1308,7 +1305,7 @@ impl, V: Clone, S, H: Hasher> HashMap { } } -impl, V: Eq, S, H: Hasher> Eq for HashMap { +impl, V: Eq, S, H: Hasher> Eq for HashMap { fn eq(&self, other: &HashMap) -> bool { if self.len() != other.len() { return false; } @@ -1321,7 +1318,7 @@ impl, V: Eq, S, H: Hasher> Eq for HashMap { } } -impl + Show, V: Show, S, H: Hasher> Show for HashMap { +impl + Show, V: Show, S, H: Hasher> Show for HashMap { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f.buf, r"\{")); @@ -1334,7 +1331,7 @@ impl + Show, V: Show, S, H: Hasher> Show for HashMap } } -impl, V, S, H: Hasher + Default> Default for HashMap { +impl, V, S, H: Hasher + Default> Default for HashMap { fn default() -> HashMap { HashMap::with_capacity_and_hasher(INITIAL_CAPACITY, Default::default()) } @@ -1358,7 +1355,7 @@ pub type Keys<'a, K, V> = pub type Values<'a, K, V> = iter::Map<'static, (&'a K, &'a V), &'a V, Entries<'a, K, V>>; -impl, V, S, H: Hasher + Default> FromIterator<(K, V)> for HashMap { +impl, V, S, H: Hasher + Default> FromIterator<(K, V)> for HashMap { fn from_iterator>(iter: &mut T) -> HashMap { let (lower, _) = iter.size_hint(); let mut map = HashMap::with_capacity_and_hasher(lower, Default::default()); @@ -1367,7 +1364,7 @@ impl, V, S, H: Hasher + Default> FromIterator<(K, V)> for Has } } -impl, V, S, H: Hasher + Default> Extendable<(K, V)> for HashMap { +impl, V, S, H: Hasher + Default> Extendable<(K, V)> for HashMap { fn extend>(&mut self, iter: &mut T) { for (k, v) in *iter { self.insert(k, v); @@ -1391,7 +1388,7 @@ pub struct HashSet { priv map: HashMap } -impl, S, H: Hasher> Eq for HashSet { +impl, S, H: Hasher> Eq for HashSet { // FIXME #11998: Since the value is a (), and `find` returns a Some(&()), // we trigger #11998 when matching on it. I've fallen back to manual // iteration until this is fixed. @@ -1402,17 +1399,17 @@ impl, S, H: Hasher> Eq for HashSet { } } -impl, S, H: Hasher> Container for HashSet { +impl, S, H: Hasher> Container for HashSet { /// Return the number of elements in the set fn len(&self) -> uint { self.map.len() } } -impl, S, H: Hasher> Mutable for HashSet { +impl, S, H: Hasher> Mutable for HashSet { /// Clear the set, removing all values. fn clear(&mut self) { self.map.clear() } } -impl, S, H: Hasher> Set for HashSet { +impl, S, H: Hasher> Set for HashSet { /// Return true if the set contains a value fn contains(&self, value: &T) -> bool { self.map.search(value).is_some() } @@ -1433,7 +1430,7 @@ impl, S, H: Hasher> Set for HashSet { } } -impl, S, H: Hasher> MutableSet for HashSet { +impl, S, H: Hasher> MutableSet for HashSet { /// Add a value to the set. Return true if the value was not already /// present in the set. fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()) } @@ -1443,7 +1440,7 @@ impl, S, H: Hasher> MutableSet for HashSet { fn remove(&mut self, value: &T) -> bool { self.map.remove(value) } } -impl HashSet { +impl HashSet { /// Create an empty HashSet pub fn new() -> HashSet { HashSet::with_capacity(INITIAL_CAPACITY) @@ -1456,7 +1453,7 @@ impl HashSet { } } -impl, S, H: Hasher> HashSet { +impl, S, H: Hasher> HashSet { pub fn with_hasher(hasher: H) -> HashSet { HashSet::with_capacity_and_hasher(INITIAL_CAPACITY, hasher) } @@ -1529,7 +1526,7 @@ impl, S, H: Hasher> HashSet { } -impl + fmt::Show, S, H: Hasher> fmt::Show for HashSet { +impl + fmt::Show, S, H: Hasher> fmt::Show for HashSet { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f.buf, r"\{")); @@ -1542,7 +1539,7 @@ impl + fmt::Show, S, H: Hasher> fmt::Show for HashSet { } } -impl, S, H: Hasher + Default> FromIterator for HashSet { +impl, S, H: Hasher + Default> FromIterator for HashSet { fn from_iterator>(iter: &mut I) -> HashSet { let (lower, _) = iter.size_hint(); let mut set = HashSet::with_capacity_and_hasher(lower, Default::default()); @@ -1551,7 +1548,7 @@ impl, S, H: Hasher + Default> FromIterator for HashSet, S, H: Hasher + Default> Extendable for HashSet { +impl, S, H: Hasher + Default> Extendable for HashSet { fn extend>(&mut self, iter: &mut I) { for k in *iter { self.insert(k); @@ -1559,7 +1556,7 @@ impl, S, H: Hasher + Default> Extendable for HashSet } } -impl Default for HashSet { +impl Default for HashSet { fn default() -> HashSet { HashSet::new() } } @@ -1601,7 +1598,7 @@ mod test_map { local_data_key!(drop_vector: vec::Vec) - #[deriving(Hash, Eq)] + #[deriving(Hash, Eq, TotalEq)] struct Dropable { k: int } diff --git a/src/libcollections/lru_cache.rs b/src/libcollections/lru_cache.rs index 28ea36fa231..e328b41cc0f 100644 --- a/src/libcollections/lru_cache.rs +++ b/src/libcollections/lru_cache.rs @@ -74,6 +74,8 @@ impl Eq for KeyRef { } } +impl TotalEq for KeyRef {} + impl LruEntry { fn new() -> LruEntry { LruEntry { @@ -94,7 +96,7 @@ impl LruEntry { } } -impl LruCache { +impl LruCache { /// Create an LRU Cache that holds at most `capacity` items. pub fn new(capacity: uint) -> LruCache { let cache = LruCache { @@ -218,7 +220,7 @@ impl LruCache { } } -impl fmt::Show for LruCache { +impl fmt::Show for LruCache { /// Return a string that lists the key-value pairs from most-recently /// used to least-recently used. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -247,14 +249,14 @@ impl fmt::Show for LruCache { } } -impl Container for LruCache { +impl Container for LruCache { /// Return the number of key-value pairs in the cache. fn len(&self) -> uint { self.map.len() } } -impl Mutable for LruCache { +impl Mutable for LruCache { /// Clear the cache of all key-value pairs. fn clear(&mut self) { self.map.clear(); diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 62e79fe8dbd..d7d936a7048 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -205,7 +205,7 @@ pub struct BorrowStats { // // Note that there is no entry with derefs:3---the type of that expression // is T, which is not a box. -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub struct root_map_key { id: ast::NodeId, derefs: uint @@ -243,13 +243,13 @@ pub enum LoanCause { RefBinding, } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum LoanPath { LpVar(ast::NodeId), // `x` in doc.rs LpExtend(@LoanPath, mc::MutabilityCategory, LoanPathElem) } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum LoanPathElem { LpDeref(mc::PointerKind), // `*LV` in doc.rs LpInterior(mc::InteriorKind) // `LV.f` in doc.rs diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 36f981f12dd..1eb6ab4a8b8 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -95,7 +95,7 @@ pub struct CopiedUpvar { } // different kinds of pointers: -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum PointerKind { OwnedPtr, GcPtr, @@ -105,26 +105,26 @@ pub enum PointerKind { // We use the term "interior" to mean "something reachable from the // base without a pointer dereference", e.g. a field -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum InteriorKind { InteriorField(FieldName), InteriorElement(ElementKind), } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum FieldName { NamedField(ast::Name), PositionalField(uint) } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum ElementKind { VecElement, StrElement, OtherElement, } -#[deriving(Eq, Hash, Show)] +#[deriving(Eq, TotalEq, Hash, Show)] pub enum MutabilityCategory { McImmutable, // Immutable. McDeclared, // Directly declared as mutable. diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 292111d7fc3..d86e05395b4 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -107,7 +107,7 @@ enum PatternBindingMode { ArgumentIrrefutableMode, } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] enum Namespace { TypeNS, ValueNS diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 9787e9228bf..78700bab3f2 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -710,7 +710,7 @@ pub fn is_null(val: ValueRef) -> bool { } // Used to identify cached monomorphized functions and vtables -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum mono_param_id { mono_precise(ty::t, Option<@Vec >), mono_any, @@ -720,7 +720,7 @@ pub enum mono_param_id { datum::RvalueMode), } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum MonoDataClass { MonoBits, // Anything not treated differently from arbitrary integer data MonoNonNull, // Non-null pointers (used for optional-pointer optimization) @@ -742,7 +742,7 @@ pub fn mono_data_classify(t: ty::t) -> MonoDataClass { } } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub struct mono_id_ { def: ast::DefId, params: Vec } diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index c334971db59..4ca2b5a47b0 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -82,7 +82,7 @@ impl Drop for Rvalue { fn drop(&mut self) { } } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum RvalueMode { /// `val` is a pointer to the actual value (and thus has type *T) ByRef, diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index e9378218ce3..425ac4f85e1 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -62,7 +62,7 @@ pub static INITIAL_DISCRIMINANT_VALUE: Disr = 0; // Data types -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub struct field { ident: ast::Ident, mt: mt @@ -123,20 +123,20 @@ pub struct Impl { ident: Ident, methods: Vec<@Method> } -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct mt { ty: t, mutbl: ast::Mutability, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash, Show)] pub enum vstore { vstore_fixed(uint), vstore_uniq, vstore_slice(Region) } -#[deriving(Clone, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Eq, TotalEq, Hash, Encodable, Decodable, Show)] pub enum TraitStore { UniqTraitStore, // ~Trait RegionTraitStore(Region), // &Trait @@ -150,7 +150,7 @@ pub struct field_ty { // Contains information needed to resolve types and (in the future) look up // the types of AST nodes. -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub struct creader_cache_key { cnum: CrateNum, pos: uint, @@ -177,6 +177,8 @@ impl cmp::Eq for intern_key { } } +impl TotalEq for intern_key {} + impl Hash for intern_key { fn hash(&self, s: &mut W) { unsafe { (*self.sty).hash(s) } @@ -382,7 +384,7 @@ pub struct t_box_ { // alive, and using ty::get is unsafe when the ctxt is no longer alive. enum t_opaque {} -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct t { priv inner: *t_opaque } impl fmt::Show for t { @@ -413,14 +415,14 @@ pub fn type_has_regions(t: t) -> bool { } pub fn type_id(t: t) -> uint { get(t).id } -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct BareFnTy { purity: ast::Purity, abis: AbiSet, sig: FnSig } -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct ClosureTy { purity: ast::Purity, sigil: ast::Sigil, @@ -442,7 +444,7 @@ pub struct ClosureTy { * - `output` is the return type. * - `variadic` indicates whether this is a varidic function. (only true for foreign fns) */ -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct FnSig { binder_id: ast::NodeId, inputs: Vec, @@ -450,14 +452,14 @@ pub struct FnSig { variadic: bool } -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct param_ty { idx: uint, def_id: DefId } /// Representation of regions: -#[deriving(Clone, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Eq, TotalEq, Hash, Encodable, Decodable, Show)] pub enum Region { // Region bound in a type or fn declaration which will be // substituted 'early' -- that is, at the same time when type @@ -498,13 +500,13 @@ pub enum Region { * the original var id (that is, the root variable that is referenced * by the upvar) and the id of the closure expression. */ -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct UpvarId { var_id: ast::NodeId, closure_expr_id: ast::NodeId, } -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub enum BorrowKind { /// Data must be immutable and is aliasable. ImmBorrow, @@ -642,7 +644,7 @@ pub enum BoundRegion { * Represents the values to use when substituting lifetime parameters. * If the value is `ErasedRegions`, then this subst is occurring during * trans, and all region parameters will be replaced with `ty::ReStatic`. */ -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub enum RegionSubsts { ErasedRegions, NonerasedRegions(OwnedSlice) @@ -665,7 +667,7 @@ pub enum RegionSubsts { * - `self_ty` is the type to which `self` should be remapped, if any. The * `self` type is rather funny in that it can only appear on traits and is * always substituted away to the implementing type for a trait. */ -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct substs { self_ty: Option, tps: Vec, @@ -720,7 +722,7 @@ mod primitives { // NB: If you change this, you'll probably want to change the corresponding // AST structure in libsyntax/ast.rs as well. -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub enum sty { ty_nil, ty_bot, @@ -755,7 +757,7 @@ pub enum sty { ty_unboxed_vec(mt), } -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct TyTrait { def_id: DefId, substs: substs, @@ -764,7 +766,7 @@ pub struct TyTrait { bounds: BuiltinBounds } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub struct TraitRef { def_id: DefId, substs: substs @@ -826,14 +828,14 @@ pub enum type_err { terr_variadic_mismatch(expected_found) } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub struct ParamBounds { builtin_bounds: BuiltinBounds, trait_bounds: Vec<@TraitRef> } pub type BuiltinBounds = EnumSet; -#[deriving(Clone, Encodable, Eq, Decodable, Hash, Show)] +#[deriving(Clone, Encodable, Eq, TotalEq, Decodable, Hash, Show)] #[repr(uint)] pub enum BuiltinBound { BoundStatic, @@ -865,28 +867,28 @@ impl CLike for BuiltinBound { } } -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct TyVid(uint); -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct IntVid(uint); -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub struct FloatVid(uint); -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct RegionVid { id: uint } -#[deriving(Clone, Eq, Hash)] +#[deriving(Clone, Eq, TotalEq, Hash)] pub enum InferTy { TyVar(TyVid), IntVar(IntVid), FloatVar(FloatVid) } -#[deriving(Clone, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Encodable, Decodable, TotalEq, Hash, Show)] pub enum InferRegion { ReVar(RegionVid), ReSkolemized(uint, BoundRegion) diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index 9d271353988..567916a59f8 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -32,7 +32,7 @@ use syntax::ast; mod doc; -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum Constraint { ConstrainVarSubVar(RegionVid, RegionVid), ConstrainRegSubVar(Region, RegionVid), @@ -40,7 +40,7 @@ pub enum Constraint { ConstrainRegSubReg(Region, Region), } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub struct TwoRegions { a: Region, b: Region, diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index b33819ff7f4..67db5b7f396 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -148,7 +148,7 @@ pub struct MethodCallee { substs: ty::substs } -#[deriving(Clone, Eq, Hash, Show)] +#[deriving(Clone, Eq, TotalEq, Hash, Show)] pub struct MethodCall { expr_id: ast::NodeId, autoderef: u32 diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index bbe3192999a..ac4db178a00 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -27,7 +27,7 @@ pub type DefIdSet = HashSet; pub mod FnvHashMap { use std::hash::Hash; use collections::HashMap; - pub fn new + Eq, V>() -> super::FnvHashMap { + pub fn new + TotalEq, V>() -> super::FnvHashMap { HashMap::with_hasher(super::FnvHasher) } } diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index 2d86734e569..bb823c2d8ca 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -165,7 +165,7 @@ impl< impl< E: Encoder, - K: Encodable + Hash + Eq, + K: Encodable + Hash + TotalEq, V: Encodable, S, H: Hasher @@ -184,7 +184,7 @@ impl< impl< D: Decoder, - K: Decodable + Hash + Eq, + K: Decodable + Hash + TotalEq, V: Decodable, S, H: Hasher + Default @@ -205,7 +205,7 @@ impl< impl< E: Encoder, - T: Encodable + Hash + Eq, + T: Encodable + Hash + TotalEq, S, H: Hasher > Encodable for HashSet { @@ -222,7 +222,7 @@ impl< impl< D: Decoder, - T: Decodable + Hash + Eq, + T: Decodable + Hash + TotalEq, S, H: Hasher + Default > Decodable for HashSet { diff --git a/src/libstd/fmt/parse.rs b/src/libstd/fmt/parse.rs index 948f85ca1c2..67088e6f4f8 100644 --- a/src/libstd/fmt/parse.rs +++ b/src/libstd/fmt/parse.rs @@ -121,7 +121,7 @@ pub enum Method<'a> { } /// A selector for what pluralization a plural method should take -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum PluralSelector { /// One of the plural keywords should be used Keyword(PluralKeyword), @@ -143,7 +143,7 @@ pub struct PluralArm<'a> { /// specially placed in the `Plural` variant of `Method` /// /// http://www.icu-project.org/apiref/icu4c/classicu_1_1PluralRules.html -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] #[allow(missing_doc)] pub enum PluralKeyword { Zero, One, Two, Few, Many diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index f654f59266a..512b20ebf4c 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -13,7 +13,7 @@ use container::Container; use c_str::{CString, ToCStr}; use clone::Clone; -use cmp::Eq; +use cmp::{Eq, TotalEq}; use from_str::FromStr; use io::Writer; use iter::{AdditiveIterator, Extendable, Iterator, Map}; @@ -69,6 +69,8 @@ impl Eq for Path { } } +impl TotalEq for Path {} + impl FromStr for Path { fn from_str(s: &str) -> Option { Path::new_opt(s) diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index dba8af4128b..81da2f50f8d 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -15,7 +15,7 @@ use c_str::{CString, ToCStr}; use cast; use clone::Clone; use container::Container; -use cmp::Eq; +use cmp::{Eq, TotalEq}; use from_str::FromStr; use io::Writer; use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Rev, Iterator, Map}; @@ -93,6 +93,8 @@ impl Eq for Path { } } +impl TotalEq for Path {} + impl FromStr for Path { fn from_str(s: &str) -> Option { Path::new_opt(s) diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index 179100255c4..504c613bf4c 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -19,7 +19,7 @@ use mem; use option::{Option, Some, None}; use intrinsics; -#[cfg(not(test))] use cmp::{Eq, Ord}; +#[cfg(not(test))] use cmp::{Eq, TotalEq, Ord}; /// Return the offset of the first null pointer in `buf`. #[inline] @@ -272,6 +272,9 @@ impl Eq for *T { fn ne(&self, other: &*T) -> bool { !self.eq(other) } } +#[cfg(not(test))] +impl TotalEq for *T {} + #[cfg(not(test))] impl Eq for *mut T { #[inline] @@ -282,6 +285,9 @@ impl Eq for *mut T { fn ne(&self, other: &*mut T) -> bool { !self.eq(other) } } +#[cfg(not(test))] +impl TotalEq for *mut T {} + // Equivalence for pointers #[cfg(not(test))] impl Equiv<*mut T> for *T { diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index 8dd06cb9232..d26038f508f 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -26,7 +26,7 @@ pointers, and then storing the parent pointers as `Weak` pointers. use cast::transmute; use cell::Cell; use clone::Clone; -use cmp::{Eq, Ord}; +use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering}; use kinds::marker; use ops::{Deref, Drop}; use option::{Option, Some, None}; @@ -127,6 +127,8 @@ impl Eq for Rc { fn ne(&self, other: &Rc) -> bool { **self != **other } } +impl TotalEq for Rc {} + impl Ord for Rc { #[inline(always)] fn lt(&self, other: &Rc) -> bool { **self < **other } @@ -141,6 +143,11 @@ impl Ord for Rc { fn ge(&self, other: &Rc) -> bool { **self >= **other } } +impl TotalOrd for Rc { + #[inline] + fn cmp(&self, other: &Rc) -> Ordering { (**self).cmp(&**other) } +} + /// Weak reference to a reference-counted box #[unsafe_no_drop_flag] pub struct Weak { diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index b159920d929..b833eea6b56 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -14,7 +14,7 @@ use std::fmt::Show; #[deriving(Eq)] pub enum Os { OsWin32, OsMacos, OsLinux, OsAndroid, OsFreebsd, } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum Abi { // NB: This ordering MUST match the AbiDatas array below. // (This is ensured by the test indices_are_correct().) @@ -65,7 +65,7 @@ pub enum AbiArchitecture { Archs(u32) // Multiple architectures (bitset) } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct AbiSet { priv bits: u32 // each bit represents one of the abis below } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f2a256165e2..24b8a345776 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -113,7 +113,7 @@ impl Decodable for Ident { /// Function name (not all functions have names) pub type FnIdent = Option; -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Lifetime { id: NodeId, span: Span, @@ -124,7 +124,7 @@ pub struct Lifetime { // for instance: std::cmp::Eq . It's represented // as a sequence of identifiers, along with a bunch // of supporting information. -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Path { span: Span, /// A `::foo` path, is relative to the crate root rather than current @@ -136,7 +136,7 @@ pub struct Path { /// A segment of a path: an identifier, an optional lifetime, and a set of /// types. -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct PathSegment { /// The identifier portion of this path segment. identifier: Ident, @@ -170,13 +170,13 @@ pub static DUMMY_NODE_ID: NodeId = -1; // typeck::collect::compute_bounds matches these against // the "special" built-in traits (see middle::lang_items) and // detects Copy, Send and Share. -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum TyParamBound { TraitTyParamBound(TraitRef), RegionTyParamBound } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct TyParam { ident: Ident, id: NodeId, @@ -184,7 +184,7 @@ pub struct TyParam { default: Option> } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Generics { lifetimes: Vec, ty_params: OwnedSlice, @@ -202,13 +202,13 @@ impl Generics { } } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum MethodProvenance { FromTrait(DefId), FromImpl(DefId), } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Def { DefFn(DefId, Purity), DefStaticMethod(/* method */ DefId, MethodProvenance, Purity), @@ -245,7 +245,7 @@ pub enum Def { DefMethod(DefId /* method */, Option /* trait */), } -#[deriving(Clone, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Eq, TotalEq, Hash, Encodable, Decodable, Show)] pub enum DefRegion { DefStaticRegion, DefEarlyBoundRegion(/* index */ uint, /* lifetime decl */ NodeId), @@ -257,7 +257,7 @@ pub enum DefRegion { // used to drive conditional compilation pub type CrateConfig = Vec<@MetaItem> ; -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Crate { module: Mod, attrs: Vec , @@ -267,7 +267,7 @@ pub struct Crate { pub type MetaItem = Spanned; -#[deriving(Clone, Encodable, Decodable, Hash)] +#[deriving(Clone, Encodable, Decodable, TotalEq, Hash)] pub enum MetaItem_ { MetaWord(InternedString), MetaList(InternedString, Vec<@MetaItem> ), @@ -299,7 +299,7 @@ impl Eq for MetaItem_ { } } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Block { view_items: Vec , stmts: Vec<@Stmt> , @@ -309,26 +309,26 @@ pub struct Block { span: Span, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Pat { id: NodeId, node: Pat_, span: Span, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct FieldPat { ident: Ident, pat: @Pat, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum BindingMode { BindByRef(Mutability), BindByValue(Mutability), } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Pat_ { PatWild, PatWildMulti, @@ -353,13 +353,13 @@ pub enum Pat_ { PatVec(Vec<@Pat> , Option<@Pat>, Vec<@Pat> ) } -#[deriving(Clone, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash, Show)] pub enum Mutability { MutMutable, MutImmutable, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Sigil { BorrowedSigil, OwnedSigil, @@ -376,14 +376,14 @@ impl fmt::Show for Sigil { } } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum ExprVstore { ExprVstoreUniq, // ~[1,2,3,4] ExprVstoreSlice, // &[1,2,3,4] ExprVstoreMutSlice, // &mut [1,2,3,4] } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum BinOp { BiAdd, BiSub, @@ -405,7 +405,7 @@ pub enum BinOp { BiGt, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum UnOp { UnBox, UnUniq, @@ -416,7 +416,7 @@ pub enum UnOp { pub type Stmt = Spanned; -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Stmt_ { // could be an item or a local (let) binding: StmtDecl(@Decl, NodeId), @@ -434,7 +434,7 @@ pub enum Stmt_ { // FIXME (pending discussion of #1697, #2178...): local should really be // a refinement on pat. /// Local represents a `let` statement, e.g., `let : = ;` -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Local { ty: P, pat: @Pat, @@ -445,7 +445,7 @@ pub struct Local { pub type Decl = Spanned; -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Decl_ { // a local (let) binding: DeclLocal(@Local), @@ -453,14 +453,14 @@ pub enum Decl_ { DeclItem(@Item), } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Arm { pats: Vec<@Pat> , guard: Option<@Expr>, body: @Expr, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Field { ident: SpannedIdent, expr: @Expr, @@ -469,26 +469,26 @@ pub struct Field { pub type SpannedIdent = Spanned; -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum UnsafeSource { CompilerGenerated, UserProvided, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Expr { id: NodeId, node: Expr_, span: Span, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Expr_ { ExprVstore(@Expr, ExprVstore), // First expr is the place; second expr is the value. @@ -557,7 +557,7 @@ pub enum Expr_ { // else knows what to do with them, so you'll probably get a syntax // error. // -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] #[doc="For macro invocations; parsing is delegated to the macro"] pub enum TokenTree { // a single token @@ -631,7 +631,7 @@ pub enum TokenTree { // pub type Matcher = Spanned; -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Matcher_ { // match one token MatchTok(::parse::token::Token), @@ -648,12 +648,12 @@ pub type Mac = Spanned; // is being invoked, and the vector of token-trees contains the source // of the macro invocation. // There's only one flavor, now, so this could presumably be simplified. -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Mac_ { MacInvocTT(Path, Vec , SyntaxContext), // new macro-invocation } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum StrStyle { CookedStr, RawStr(uint) @@ -661,7 +661,7 @@ pub enum StrStyle { pub type Lit = Spanned; -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Lit_ { LitStr(InternedString, StrStyle), LitBinary(Rc >), @@ -677,20 +677,20 @@ pub enum Lit_ { // NB: If you change this, you'll probably want to change the corresponding // type structure in middle/ty.rs as well. -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct MutTy { ty: P, mutbl: Mutability, } -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub struct TypeField { ident: Ident, mt: MutTy, span: Span, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct TypeMethod { ident: Ident, attrs: Vec , @@ -705,13 +705,13 @@ pub struct TypeMethod { // A trait method is either required (meaning it doesn't have an // implementation, just a signature) or provided (meaning it has a default // implementation). -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum TraitMethod { Required(TypeMethod), Provided(@Method), } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum IntTy { TyI, TyI8, @@ -726,7 +726,7 @@ impl fmt::Show for IntTy { } } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum UintTy { TyU, TyU8, @@ -741,7 +741,7 @@ impl fmt::Show for UintTy { } } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum FloatTy { TyF32, TyF64, @@ -754,7 +754,7 @@ impl fmt::Show for FloatTy { } // NB Eq method appears below. -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Ty { id: NodeId, node: Ty_, @@ -762,7 +762,7 @@ pub struct Ty { } // Not represented directly in the AST, referred to by name through a ty_path. -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum PrimTy { TyInt(IntTy), TyUint(UintTy), @@ -772,7 +772,7 @@ pub enum PrimTy { TyChar } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Onceness { Once, Many @@ -787,7 +787,7 @@ impl fmt::Show for Onceness { } } -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub struct ClosureTy { sigil: Sigil, region: Option, @@ -802,7 +802,7 @@ pub struct ClosureTy { bounds: Option>, } -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub struct BareFnTy { purity: Purity, abis: AbiSet, @@ -810,7 +810,7 @@ pub struct BareFnTy { decl: P } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Ty_ { TyNil, TyBot, /* bottom type */ @@ -830,13 +830,13 @@ pub enum Ty_ { TyInfer, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum AsmDialect { AsmAtt, AsmIntel } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct InlineAsm { asm: InternedString, asm_str_style: StrStyle, @@ -848,7 +848,7 @@ pub struct InlineAsm { dialect: AsmDialect } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Arg { ty: P, pat: @Pat, @@ -875,7 +875,7 @@ impl Arg { } } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct FnDecl { inputs: Vec , output: P, @@ -883,7 +883,7 @@ pub struct FnDecl { variadic: bool } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Purity { UnsafeFn, // declared with "unsafe fn" ImpureFn, // declared with "fn" @@ -900,14 +900,14 @@ impl fmt::Show for Purity { } } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum RetStyle { NoReturn, // functions with return type _|_ that always // raise an error or exit (i.e. never return to the caller) Return, // everything else } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum ExplicitSelf_ { SelfStatic, // no self SelfValue, // `self` @@ -917,7 +917,7 @@ pub enum ExplicitSelf_ { pub type ExplicitSelf = Spanned; -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Method { ident: Ident, attrs: Vec , @@ -931,37 +931,37 @@ pub struct Method { vis: Visibility, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Mod { view_items: Vec , items: Vec<@Item> , } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct ForeignMod { abis: AbiSet, view_items: Vec , items: Vec<@ForeignItem> , } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct VariantArg { ty: P, id: NodeId, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum VariantKind { TupleVariantKind(Vec ), StructVariantKind(@StructDef), } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct EnumDef { variants: Vec> , } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Variant_ { name: Ident, attrs: Vec , @@ -973,7 +973,7 @@ pub struct Variant_ { pub type Variant = Spanned; -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct PathListIdent_ { name: Ident, id: NodeId, @@ -983,7 +983,7 @@ pub type PathListIdent = Spanned; pub type ViewPath = Spanned; -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub enum ViewPath_ { // quux = foo::bar::baz @@ -1000,7 +1000,7 @@ pub enum ViewPath_ { ViewPathList(Path, Vec , NodeId) } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct ViewItem { node: ViewItem_, attrs: Vec , @@ -1008,7 +1008,7 @@ pub struct ViewItem { span: Span, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum ViewItem_ { // ident: name used to refer to this crate in the code // optional (InternedString,StrStyle): if present, this is a location @@ -1024,14 +1024,14 @@ pub type Attribute = Spanned; // Distinguishes between Attributes that decorate items and Attributes that // are contained as statements within items. These two cases need to be // distinguished for pretty-printing. -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum AttrStyle { AttrOuter, AttrInner, } // doc-comments are promoted to attributes that have is_sugared_doc = true -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Attribute_ { style: AttrStyle, value: @MetaItem, @@ -1045,13 +1045,13 @@ pub struct Attribute_ { If this impl is an ItemImpl, the impl_id is redundant (it could be the same as the impl's node id). */ -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct TraitRef { path: Path, ref_id: NodeId, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Visibility { Public, Private, @@ -1067,7 +1067,7 @@ impl Visibility { } } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct StructField_ { kind: StructFieldKind, id: NodeId, @@ -1077,13 +1077,13 @@ pub struct StructField_ { pub type StructField = Spanned; -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum StructFieldKind { NamedField(Ident, Visibility), UnnamedField // element of a tuple-like struct } -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub struct StructDef { fields: Vec , /* fields, not including ctor */ /* ID of the constructor. This is only used for tuple- or enum-like @@ -1095,7 +1095,7 @@ pub struct StructDef { FIXME (#3300): Should allow items to be anonymous. Right now we just use dummy names for anon items. */ -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Item { ident: Ident, attrs: Vec , @@ -1105,7 +1105,7 @@ pub struct Item { span: Span, } -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub enum Item_ { ItemStatic(P, Mutability, @Expr), ItemFn(P, Purity, AbiSet, Generics, P), @@ -1123,7 +1123,7 @@ pub enum Item_ { ItemMac(Mac), } -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub struct ForeignItem { ident: Ident, attrs: Vec , @@ -1133,7 +1133,7 @@ pub struct ForeignItem { vis: Visibility, } -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub enum ForeignItem_ { ForeignItemFn(P, Generics), ForeignItemStatic(P, /* is_mutbl */ bool), @@ -1142,7 +1142,7 @@ pub enum ForeignItem_ { // The data we save and restore about an inlined item or method. This is not // part of the AST that we parse from a file, but it becomes part of the tree // that we trans. -#[deriving(Eq, Encodable, Decodable, Hash)] +#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)] pub enum InlinedItem { IIItem(@Item), IIMethod(DefId /* impl id */, bool /* is provided */, @Method), diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 4ba7921c431..325df5fda60 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -22,7 +22,6 @@ source code snippets, etc. */ use std::cell::RefCell; -use std::cmp; use std::rc::Rc; use serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -33,7 +32,7 @@ pub trait Pos { /// A byte offset. Keep this small (currently 32-bits), as AST contains /// a lot of them. -#[deriving(Clone, Eq, Hash, Ord, Show)] +#[deriving(Clone, Eq, TotalEq, Hash, Ord, Show)] pub struct BytePos(u32); /// A character offset. Because of multibyte utf8 characters, a byte offset @@ -94,19 +93,21 @@ pub struct Span { pub static DUMMY_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_info: None }; -#[deriving(Clone, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Spanned { node: T, span: Span, } -impl cmp::Eq for Span { +impl Eq for Span { fn eq(&self, other: &Span) -> bool { return (*self).lo == (*other).lo && (*self).hi == (*other).hi; } fn ne(&self, other: &Span) -> bool { !(*self).eq(other) } } +impl TotalEq for Span {} + impl Encodable for Span { /* Note #1972 -- spans are encoded but not decoded */ fn encode(&self, s: &mut S) { diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs index df38945f198..d5b90821897 100644 --- a/src/libsyntax/owned_slice.rs +++ b/src/libsyntax/owned_slice.rs @@ -119,6 +119,8 @@ impl Eq for OwnedSlice { } } +impl TotalEq for OwnedSlice {} + impl Container for OwnedSlice { fn len(&self) -> uint { self.len } } diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 1d7bf2ef6da..63b3fb09ee3 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -23,7 +23,7 @@ use parse::parser::Parser; use parse::token; /// The specific types of unsupported syntax -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] pub enum ObsoleteSyntax { ObsoleteSwap, ObsoleteUnsafeBlock, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index eebb98294d5..15525912955 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -24,7 +24,7 @@ use std::local_data; use std::path::BytesContainer; #[allow(non_camel_case_types)] -#[deriving(Clone, Encodable, Decodable, Eq, Hash, Show)] +#[deriving(Clone, Encodable, Decodable, Eq, TotalEq, Hash, Show)] pub enum BinOp { PLUS, MINUS, @@ -39,7 +39,7 @@ pub enum BinOp { } #[allow(non_camel_case_types)] -#[deriving(Clone, Encodable, Decodable, Eq, Hash, Show)] +#[deriving(Clone, Encodable, Decodable, Eq, TotalEq, Hash, Show)] pub enum Token { /* Expression-operator symbols. */ EQ, @@ -103,7 +103,7 @@ pub enum Token { EOF, } -#[deriving(Clone, Encodable, Decodable, Eq, Hash)] +#[deriving(Clone, Encodable, Decodable, Eq, TotalEq, Hash)] /// For interpolation during macro expansion. pub enum Nonterminal { NtItem(@ast::Item), diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index d6f8f1067ae..9b73cf533a7 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -28,7 +28,7 @@ pub struct Interner { } // when traits can extend traits, we should extend index to get [] -impl Interner { +impl Interner { pub fn new() -> Interner { Interner { map: RefCell::new(HashMap::new()), diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index 8a3881e801a..222aff37465 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -424,7 +424,7 @@ pub fn write_boxplot(w: &mut io::Writer, s: &Summary, /// Returns a HashMap with the number of occurrences of every element in the /// sequence that the iterator exposes. -pub fn freq_count, U: Eq+Hash>(mut iter: T) -> hashmap::HashMap { +pub fn freq_count, U: TotalEq+Hash>(mut iter: T) -> hashmap::HashMap { let mut map: hashmap::HashMap = hashmap::HashMap::new(); for elem in iter { map.insert_or_update_with(elem, 1, |_, count| *count += 1); diff --git a/src/test/run-pass/issue-12860.rs b/src/test/run-pass/issue-12860.rs index 52eafaadfd4..3876aa45753 100644 --- a/src/test/run-pass/issue-12860.rs +++ b/src/test/run-pass/issue-12860.rs @@ -14,7 +14,7 @@ extern crate collections; use collections::HashSet; -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] struct XYZ { x: int, y: int, diff --git a/src/test/run-pass/regions-mock-tcx.rs b/src/test/run-pass/regions-mock-tcx.rs index 7c87c858d42..c38df0f7a22 100644 --- a/src/test/run-pass/regions-mock-tcx.rs +++ b/src/test/run-pass/regions-mock-tcx.rs @@ -42,6 +42,8 @@ impl<'tcx> Eq for TypeStructure<'tcx> { } } +impl<'tcx> TotalEq for TypeStructure<'tcx> {} + struct TypeContext<'tcx, 'ast> { ty_arena: &'tcx Arena, types: Vec> , @@ -86,7 +88,7 @@ impl<'tcx,'ast> TypeContext<'tcx, 'ast> { } } -#[deriving(Eq, Hash)] +#[deriving(Eq, TotalEq, Hash)] struct NodeId { id: uint }