Round 2 test fixes and conflicts
This commit is contained in:
parent
231eeaa35b
commit
3e7a04cb3c
3 changed files with 131 additions and 27 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue