Skip to content

Commit d223dd1

Browse files
committed
std: rewrite Hash to make it more generic
This patch merges IterBytes and Hash traits, which clears up the confusion of using `#[deriving(IterBytes)]` to support hashing. Instead, it now is much easier to use the new `#[deriving(Hash)]` for making a type hashable with a stream hash. Furthermore, it supports custom non-stream-based hashers, such as if a value's hash was cached in a database. This does not yet replace the old IterBytes-hash with this new version.
1 parent 0135b52 commit d223dd1

25 files changed

+1154
-15
lines changed

src/etc/generate-deriving-span-tests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def write_file(name, string):
119119
('Clone', [], 1), ('DeepClone', ['Clone'], 1),
120120
('Eq', [], 2), ('Ord', [], 8),
121121
('TotalEq', [], 1), ('TotalOrd', ['TotalEq'], 1),
122-
('Show', [], 1)]:
122+
('Show', [], 1),
123+
('Hash', [], 1)]:
123124
traits[trait] = (ALL, supers, errs)
124125

125126
for (trait, (types, super_traits, error_count)) in traits.items():

src/libextra/stats.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#[allow(missing_doc)];
1212

1313
use std::cmp;
14+
use std::hash_old::Hash;
1415
use std::hashmap;
1516
use std::io;
1617
use std::mem;

src/librustc/metadata/decoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use middle::typeck;
2727
use middle::astencode::vtable_decoder_helpers;
2828

2929
use std::u64;
30+
use std::hash_old::Hash;
3031
use std::io;
3132
use std::io::extensions::u64_from_be_bytes;
3233
use std::option;

src/librustc/metadata/encoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use middle;
2626
use serialize::Encodable;
2727
use std::cast;
2828
use std::cell::{Cell, RefCell};
29+
use std::hash_old::Hash;
2930
use std::hashmap::{HashMap, HashSet};
3031
use std::io::MemWriter;
3132
use std::str;

src/librustc/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4916,7 +4916,7 @@ pub fn trait_method_of_method(tcx: ctxt,
49164916
/// Creates a hash of the type `t` which will be the same no matter what crate
49174917
/// context it's calculated within. This is used by the `type_id` intrinsic.
49184918
pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
4919-
use std::hash::{SipState, Streaming};
4919+
use std::hash_old::{SipState, Streaming};
49204920

49214921
let mut hash = SipState::new(0, 0);
49224922
let region = |_hash: &mut SipState, r: Region| {

src/libserialize/serialize.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Core encoding and decoding interfaces.
1515
*/
1616

17+
use std::hash_old::Hash;
1718
use std::hashmap::{HashMap, HashSet};
1819
use std::rc::Rc;
1920
use std::trie::{TrieMap, TrieSet};

0 commit comments

Comments
 (0)