Skip to content

Commit 855a325

Browse files
committed
---
yaml --- r: 184015 b: refs/heads/auto c: 3e7a04c h: refs/heads/master i: 184013: 66b40fc 184011: 03d517a 184007: e794ce0 183999: 5ea3974 v: v3
1 parent af17f9b commit 855a325

File tree

4 files changed

+132
-28
lines changed

4 files changed

+132
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 231eeaa35b3a7700cfd05dcb30f01cd7a36313b8
13+
refs/heads/auto: 3e7a04cb3cac2b803dc8188d9a55ba1836404ea3
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libcore/hash/mod.rs

Lines changed: 115 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ pub fn hash<T: Hash, H: Hasher + Default>(value: &T) -> u64 {
231231
mod impls {
232232
use prelude::*;
233233

234-
use borrow::{Cow, ToOwned};
235234
use mem;
236235
use num::Int;
237236
use super::*;
@@ -364,22 +363,12 @@ mod impls {
364363
(*self as uint).hash(state);
365364
}
366365
}
367-
368-
impl<'a, T, B: ?Sized, S: Hasher> Hash<S> for Cow<'a, T, B>
369-
where B: Hash<S> + ToOwned<T>
370-
{
371-
#[inline]
372-
fn hash(&self, state: &mut S) {
373-
Hash::hash(&**self, state)
374-
}
375-
}
376366
}
377367

378368
#[cfg(not(stage0))]
379369
mod impls {
380370
use prelude::*;
381371

382-
use borrow::{Cow, ToOwned};
383372
use slice;
384373
use super::*;
385374

@@ -399,4 +388,119 @@ mod impls {
399388
}
400389
)*}
401390
}
391+
392+
impl_write! {
393+
(u8, write_u8),
394+
(u16, write_u16),
395+
(u32, write_u32),
396+
(u64, write_u64),
397+
(usize, write_usize),
398+
(i8, write_i8),
399+
(i16, write_i16),
400+
(i32, write_i32),
401+
(i64, write_i64),
402+
(isize, write_isize),
403+
}
404+
405+
#[stable(feature = "rust1", since = "1.0.0")]
406+
impl Hash for bool {
407+
fn hash<H: Hasher>(&self, state: &mut H) {
408+
state.write_u8(*self as u8)
409+
}
410+
}
411+
412+
#[stable(feature = "rust1", since = "1.0.0")]
413+
impl Hash for char {
414+
fn hash<H: Hasher>(&self, state: &mut H) {
415+
state.write_u32(*self as u32)
416+
}
417+
}
418+
419+
#[stable(feature = "rust1", since = "1.0.0")]
420+
impl Hash for str {
421+
fn hash<H: Hasher>(&self, state: &mut H) {
422+
state.write(self.as_bytes());
423+
state.write_u8(0xff)
424+
}
425+
}
426+
427+
macro_rules! impl_hash_tuple {
428+
() => (
429+
#[stable(feature = "rust1", since = "1.0.0")]
430+
impl Hash for () {
431+
fn hash<H: Hasher>(&self, _state: &mut H) {}
432+
}
433+
);
434+
435+
( $($name:ident)+) => (
436+
#[stable(feature = "rust1", since = "1.0.0")]
437+
impl<$($name: Hash),*> Hash for ($($name,)*) {
438+
#[allow(non_snake_case)]
439+
fn hash<S: Hasher>(&self, state: &mut S) {
440+
let ($(ref $name,)*) = *self;
441+
$($name.hash(state);)*
442+
}
443+
}
444+
);
445+
}
446+
447+
impl_hash_tuple! {}
448+
impl_hash_tuple! { A }
449+
impl_hash_tuple! { A B }
450+
impl_hash_tuple! { A B C }
451+
impl_hash_tuple! { A B C D }
452+
impl_hash_tuple! { A B C D E }
453+
impl_hash_tuple! { A B C D E F }
454+
impl_hash_tuple! { A B C D E F G }
455+
impl_hash_tuple! { A B C D E F G H }
456+
impl_hash_tuple! { A B C D E F G H I }
457+
impl_hash_tuple! { A B C D E F G H I J }
458+
impl_hash_tuple! { A B C D E F G H I J K }
459+
impl_hash_tuple! { A B C D E F G H I J K L }
460+
461+
#[stable(feature = "rust1", since = "1.0.0")]
462+
impl<T: Hash> Hash for [T] {
463+
fn hash<H: Hasher>(&self, state: &mut H) {
464+
self.len().hash(state);
465+
Hash::hash_slice(self, state)
466+
}
467+
}
468+
469+
470+
#[stable(feature = "rust1", since = "1.0.0")]
471+
impl<'a, T: ?Sized + Hash> Hash for &'a T {
472+
fn hash<H: Hasher>(&self, state: &mut H) {
473+
(**self).hash(state);
474+
}
475+
}
476+
477+
#[stable(feature = "rust1", since = "1.0.0")]
478+
impl<'a, T: ?Sized + Hash> Hash for &'a mut T {
479+
fn hash<H: Hasher>(&self, state: &mut H) {
480+
(**self).hash(state);
481+
}
482+
}
483+
484+
#[stable(feature = "rust1", since = "1.0.0")]
485+
impl<T> Hash for *const T {
486+
fn hash<H: Hasher>(&self, state: &mut H) {
487+
state.write_usize(*self as usize)
488+
}
489+
}
490+
491+
#[stable(feature = "rust1", since = "1.0.0")]
492+
impl<T> Hash for *mut T {
493+
fn hash<H: Hasher>(&self, state: &mut H) {
494+
state.write_usize(*self as usize)
495+
}
496+
}
497+
498+
#[stable(feature = "rust1", since = "1.0.0")]
499+
impl<'a, T, B: ?Sized> Hash for Cow<'a, T, B>
500+
where B: Hash + ToOwned<T>
501+
{
502+
fn hash<H: Hasher>(&self, state: &mut H) {
503+
Hash::hash(&**self, state)
504+
}
505+
}
402506
}

branches/auto/src/libstd/collections/hash/map_stage0.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use self::Entry::*;
1414
use self::SearchResult::*;
1515
use self::VacantEntryState::*;
1616

17-
use borrow::BorrowFrom;
17+
use borrow::Borrow;
1818
use clone::Clone;
1919
use cmp::{max, Eq, PartialEq};
2020
use default::Default;
@@ -453,18 +453,18 @@ impl<K, V, S, H> HashMap<K, V, S>
453453
/// If you already have the hash for the key lying around, use
454454
/// search_hashed.
455455
fn search<'a, Q: ?Sized>(&'a self, q: &Q) -> Option<FullBucketImm<'a, K, V>>
456-
where Q: BorrowFrom<K> + Eq + Hash<H>
456+
where K: Borrow<Q>, Q: Eq + Hash<H>
457457
{
458458
let hash = self.make_hash(q);
459-
search_hashed(&self.table, hash, |k| q.eq(BorrowFrom::borrow_from(k)))
459+
search_hashed(&self.table, hash, |k| q.eq(k.borrow()))
460460
.into_option()
461461
}
462462

463463
fn search_mut<'a, Q: ?Sized>(&'a mut self, q: &Q) -> Option<FullBucketMut<'a, K, V>>
464-
where Q: BorrowFrom<K> + Eq + Hash<H>
464+
where K: Borrow<Q>, Q: Eq + Hash<H>
465465
{
466466
let hash = self.make_hash(q);
467-
search_hashed(&mut self.table, hash, |k| q.eq(BorrowFrom::borrow_from(k)))
467+
search_hashed(&mut self.table, hash, |k| q.eq(k.borrow()))
468468
.into_option()
469469
}
470470

@@ -1037,7 +1037,7 @@ impl<K, V, S, H> HashMap<K, V, S>
10371037
/// ```
10381038
#[stable(feature = "rust1", since = "1.0.0")]
10391039
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
1040-
where Q: Hash<H> + Eq + BorrowFrom<K>
1040+
where K: Borrow<Q>, Q: Hash<H> + Eq
10411041
{
10421042
self.search(k).map(|bucket| bucket.into_refs().1)
10431043
}
@@ -1060,7 +1060,7 @@ impl<K, V, S, H> HashMap<K, V, S>
10601060
/// ```
10611061
#[stable(feature = "rust1", since = "1.0.0")]
10621062
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
1063-
where Q: Hash<H> + Eq + BorrowFrom<K>
1063+
where K: Borrow<Q>, Q: Hash<H> + Eq
10641064
{
10651065
self.search(k).is_some()
10661066
}
@@ -1086,7 +1086,7 @@ impl<K, V, S, H> HashMap<K, V, S>
10861086
/// ```
10871087
#[stable(feature = "rust1", since = "1.0.0")]
10881088
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
1089-
where Q: Hash<H> + Eq + BorrowFrom<K>
1089+
where K: Borrow<Q>, Q: Hash<H> + Eq
10901090
{
10911091
self.search_mut(k).map(|bucket| bucket.into_mut_refs().1)
10921092
}
@@ -1138,7 +1138,7 @@ impl<K, V, S, H> HashMap<K, V, S>
11381138
/// ```
11391139
#[stable(feature = "rust1", since = "1.0.0")]
11401140
pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
1141-
where Q: Hash<H> + Eq + BorrowFrom<K>
1141+
where K: Borrow<Q>, Q: Hash<H> + Eq
11421142
{
11431143
if self.table.size() == 0 {
11441144
return None
@@ -1247,8 +1247,8 @@ impl<K, V, S, H> Default for HashMap<K, V, S>
12471247

12481248
#[stable(feature = "rust1", since = "1.0.0")]
12491249
impl<K, Q: ?Sized, V, S, H> Index<Q> for HashMap<K, V, S>
1250-
where K: Eq + Hash<H>,
1251-
Q: Eq + Hash<H> + BorrowFrom<K>,
1250+
where K: Eq + Hash<H> + Borrow<Q>,
1251+
Q: Eq + Hash<H>,
12521252
S: HashState<Hasher=H>,
12531253
H: hash::Hasher<Output=u64>
12541254
{
@@ -1262,8 +1262,8 @@ impl<K, Q: ?Sized, V, S, H> Index<Q> for HashMap<K, V, S>
12621262

12631263
#[stable(feature = "rust1", since = "1.0.0")]
12641264
impl<K, V, S, H, Q: ?Sized> IndexMut<Q> for HashMap<K, V, S>
1265-
where K: Eq + Hash<H>,
1266-
Q: Eq + Hash<H> + BorrowFrom<K>,
1265+
where K: Eq + Hash<H> + Borrow<Q>,
1266+
Q: Eq + Hash<H>,
12671267
S: HashState<Hasher=H>,
12681268
H: hash::Hasher<Output=u64>
12691269
{

branches/auto/src/libstd/collections/hash/set_stage0.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
// ignore-lexer-test FIXME #15883
1212

13-
use borrow::BorrowFrom;
13+
use borrow::Borrow;
1414
use clone::Clone;
1515
use cmp::{Eq, PartialEq};
1616
use core::marker::Sized;
@@ -462,7 +462,7 @@ impl<T, S, H> HashSet<T, S>
462462
/// ```
463463
#[stable(feature = "rust1", since = "1.0.0")]
464464
pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool
465-
where Q: BorrowFrom<T> + Hash<H> + Eq
465+
where T: Borrow<Q>, Q: Hash<H> + Eq
466466
{
467467
self.map.contains_key(value)
468468
}
@@ -572,7 +572,7 @@ impl<T, S, H> HashSet<T, S>
572572
/// ```
573573
#[stable(feature = "rust1", since = "1.0.0")]
574574
pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool
575-
where Q: BorrowFrom<T> + Hash<H> + Eq
575+
where T: Borrow<Q>, Q: Hash<H> + Eq
576576
{
577577
self.map.remove(value).is_some()
578578
}

0 commit comments

Comments
 (0)