diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-02-18 15:48:45 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-02-18 15:48:45 -0800 |
| commit | 3e7a04cb3cac2b803dc8188d9a55ba1836404ea3 (patch) | |
| tree | e1dfe6c31004598375c57a042d81ab69eca1f068 /src | |
| parent | 231eeaa35b3a7700cfd05dcb30f01cd7a36313b8 (diff) | |
| download | rust-3e7a04cb3cac2b803dc8188d9a55ba1836404ea3.tar.gz rust-3e7a04cb3cac2b803dc8188d9a55ba1836404ea3.zip | |
Round 2 test fixes and conflicts
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/hash/mod.rs | 126 | ||||
| -rw-r--r-- | src/libstd/collections/hash/map_stage0.rs | 26 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set_stage0.rs | 6 |
3 files changed, 131 insertions, 27 deletions
diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 3d0c9761dda..1bd8aa0a17e 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -231,7 +231,6 @@ pub fn hash<T: Hash, H: Hasher + Default>(value: &T) -> u64 { mod impls { use prelude::*; - use borrow::{Cow, ToOwned}; use mem; use num::Int; use super::*; @@ -364,22 +363,12 @@ mod impls { (*self as uint).hash(state); } } - - impl<'a, T, B: ?Sized, S: Hasher> Hash<S> for Cow<'a, T, B> - where B: Hash<S> + ToOwned<T> - { - #[inline] - fn hash(&self, state: &mut S) { - Hash::hash(&**self, state) - } - } } #[cfg(not(stage0))] mod impls { use prelude::*; - use borrow::{Cow, ToOwned}; use slice; use super::*; @@ -399,4 +388,119 @@ mod impls { } )*} } + + impl_write! { + (u8, write_u8), + (u16, write_u16), + (u32, write_u32), + (u64, write_u64), + (usize, write_usize), + (i8, write_i8), + (i16, write_i16), + (i32, write_i32), + (i64, write_i64), + (isize, write_isize), + } + + #[stable(feature = "rust1", since = "1.0.0")] + impl Hash for bool { + fn hash<H: Hasher>(&self, state: &mut H) { + state.write_u8(*self as u8) + } + } + + #[stable(feature = "rust1", since = "1.0.0")] + impl Hash for char { + fn hash<H: Hasher>(&self, state: &mut H) { + state.write_u32(*self as u32) + } + } + + #[stable(feature = "rust1", since = "1.0.0")] + impl Hash for str { + fn hash<H: Hasher>(&self, state: &mut H) { + state.write(self.as_bytes()); + state.write_u8(0xff) + } + } + + macro_rules! impl_hash_tuple { + () => ( + #[stable(feature = "rust1", since = "1.0.0")] + impl Hash for () { + fn hash<H: Hasher>(&self, _state: &mut H) {} + } + ); + + ( $($name:ident)+) => ( + #[stable(feature = "rust1", since = "1.0.0")] + impl<$($name: Hash),*> Hash for ($($name,)*) { + #[allow(non_snake_case)] + fn hash<S: Hasher>(&self, state: &mut S) { + let ($(ref $name,)*) = *self; + $($name.hash(state);)* + } + } + ); + } + + impl_hash_tuple! {} + impl_hash_tuple! { A } + impl_hash_tuple! { A B } + impl_hash_tuple! { A B C } + impl_hash_tuple! { A B C D } + impl_hash_tuple! { A B C D E } + impl_hash_tuple! { A B C D E F } + impl_hash_tuple! { A B C D E F G } + impl_hash_tuple! { A B C D E F G H } + impl_hash_tuple! { A B C D E F G H I } + impl_hash_tuple! { A B C D E F G H I J } + impl_hash_tuple! { A B C D E F G H I J K } + impl_hash_tuple! { A B C D E F G H I J K L } + + #[stable(feature = "rust1", since = "1.0.0")] + impl<T: Hash> Hash for [T] { + fn hash<H: Hasher>(&self, state: &mut H) { + self.len().hash(state); + Hash::hash_slice(self, state) + } + } + + + #[stable(feature = "rust1", since = "1.0.0")] + impl<'a, T: ?Sized + Hash> Hash for &'a T { + fn hash<H: Hasher>(&self, state: &mut H) { + (**self).hash(state); + } + } + + #[stable(feature = "rust1", since = "1.0.0")] + impl<'a, T: ?Sized + Hash> Hash for &'a mut T { + fn hash<H: Hasher>(&self, state: &mut H) { + (**self).hash(state); + } + } + + #[stable(feature = "rust1", since = "1.0.0")] + impl<T> Hash for *const T { + fn hash<H: Hasher>(&self, state: &mut H) { + state.write_usize(*self as usize) + } + } + + #[stable(feature = "rust1", since = "1.0.0")] + impl<T> Hash for *mut T { + fn hash<H: Hasher>(&self, state: &mut H) { + state.write_usize(*self as usize) + } + } + + #[stable(feature = "rust1", since = "1.0.0")] + impl<'a, T, B: ?Sized> Hash for Cow<'a, T, B> + where B: Hash + ToOwned<T> + { + fn hash<H: Hasher>(&self, state: &mut H) { + Hash::hash(&**self, state) + } + } } diff --git a/src/libstd/collections/hash/map_stage0.rs b/src/libstd/collections/hash/map_stage0.rs index 8ae195cf991..f9e5044c597 100644 --- a/src/libstd/collections/hash/map_stage0.rs +++ b/src/libstd/collections/hash/map_stage0.rs @@ -14,7 +14,7 @@ use self::Entry::*; use self::SearchResult::*; use self::VacantEntryState::*; -use borrow::BorrowFrom; +use borrow::Borrow; use clone::Clone; use cmp::{max, Eq, PartialEq}; use default::Default; @@ -453,18 +453,18 @@ impl<K, V, S, H> HashMap<K, V, S> /// If you already have the hash for the key lying around, use /// search_hashed. fn search<'a, Q: ?Sized>(&'a self, q: &Q) -> Option<FullBucketImm<'a, K, V>> - where Q: BorrowFrom<K> + Eq + Hash<H> + where K: Borrow<Q>, Q: Eq + Hash<H> { let hash = self.make_hash(q); - search_hashed(&self.table, hash, |k| q.eq(BorrowFrom::borrow_from(k))) + search_hashed(&self.table, hash, |k| q.eq(k.borrow())) .into_option() } fn search_mut<'a, Q: ?Sized>(&'a mut self, q: &Q) -> Option<FullBucketMut<'a, K, V>> - where Q: BorrowFrom<K> + Eq + Hash<H> + where K: Borrow<Q>, Q: Eq + Hash<H> { let hash = self.make_hash(q); - search_hashed(&mut self.table, hash, |k| q.eq(BorrowFrom::borrow_from(k))) + search_hashed(&mut self.table, hash, |k| q.eq(k.borrow())) .into_option() } @@ -1037,7 +1037,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V> - where Q: Hash<H> + Eq + BorrowFrom<K> + where K: Borrow<Q>, Q: Hash<H> + Eq { self.search(k).map(|bucket| bucket.into_refs().1) } @@ -1060,7 +1060,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool - where Q: Hash<H> + Eq + BorrowFrom<K> + where K: Borrow<Q>, Q: Hash<H> + Eq { self.search(k).is_some() } @@ -1086,7 +1086,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V> - where Q: Hash<H> + Eq + BorrowFrom<K> + where K: Borrow<Q>, Q: Hash<H> + Eq { self.search_mut(k).map(|bucket| bucket.into_mut_refs().1) } @@ -1138,7 +1138,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V> - where Q: Hash<H> + Eq + BorrowFrom<K> + where K: Borrow<Q>, Q: Hash<H> + Eq { if self.table.size() == 0 { return None @@ -1247,8 +1247,8 @@ impl<K, V, S, H> Default for HashMap<K, V, S> #[stable(feature = "rust1", since = "1.0.0")] impl<K, Q: ?Sized, V, S, H> Index<Q> for HashMap<K, V, S> - where K: Eq + Hash<H>, - Q: Eq + Hash<H> + BorrowFrom<K>, + where K: Eq + Hash<H> + Borrow<Q>, + Q: Eq + Hash<H>, S: HashState<Hasher=H>, H: hash::Hasher<Output=u64> { @@ -1262,8 +1262,8 @@ impl<K, Q: ?Sized, V, S, H> Index<Q> for HashMap<K, V, S> #[stable(feature = "rust1", since = "1.0.0")] impl<K, V, S, H, Q: ?Sized> IndexMut<Q> for HashMap<K, V, S> - where K: Eq + Hash<H>, - Q: Eq + Hash<H> + BorrowFrom<K>, + where K: Eq + Hash<H> + Borrow<Q>, + Q: Eq + Hash<H>, S: HashState<Hasher=H>, H: hash::Hasher<Output=u64> { diff --git a/src/libstd/collections/hash/set_stage0.rs b/src/libstd/collections/hash/set_stage0.rs index 9d615d0c3ff..68c9e02d8ad 100644 --- a/src/libstd/collections/hash/set_stage0.rs +++ b/src/libstd/collections/hash/set_stage0.rs @@ -10,7 +10,7 @@ // // ignore-lexer-test FIXME #15883 -use borrow::BorrowFrom; +use borrow::Borrow; use clone::Clone; use cmp::{Eq, PartialEq}; use core::marker::Sized; @@ -462,7 +462,7 @@ impl<T, S, H> HashSet<T, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool - where Q: BorrowFrom<T> + Hash<H> + Eq + where T: Borrow<Q>, Q: Hash<H> + Eq { self.map.contains_key(value) } @@ -572,7 +572,7 @@ impl<T, S, H> HashSet<T, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool - where Q: BorrowFrom<T> + Hash<H> + Eq + where T: Borrow<Q>, Q: Hash<H> + Eq { self.map.remove(value).is_some() } |
