1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 #![feature(hash_default)]
14 use std
::hash
::{Hash, SipHasher, Hasher}
;
15 use std
::mem
::size_of
;
24 // test for hygiene name collisions
25 #[derive(Hash)] struct __H__H;
26 #[derive(Hash)] enum Collision<__H> { __H { __H__H: __H } }
31 fn hash
<T
: Hash
>(t
: &T
) -> u64 {
32 let mut s
= SipHasher
::new_with_keys(0, 0);
37 struct FakeHasher
<'a
>(&'a
mut Vec
<u8>);
38 impl<'a
> Hasher
for FakeHasher
<'a
> {
39 fn finish(&self) -> u64 {
43 fn write(&mut self, bytes
: &[u8]) {
48 fn fake_hash(v
: &mut Vec
<u8>, e
: E
) {
49 e
.hash(&mut FakeHasher(v
));
53 let person1
= Person
{
55 name
: "Janet".to_string(),
58 let person2
= Person
{
60 name
: "Bob".to_string(),
63 assert_eq
!(hash(&person1
), hash(&person1
));
64 assert
!(hash(&person1
) != hash(&person2
));
69 fake_hash(&mut va
, E
::A
);
70 fake_hash(&mut vb
, E
::B
);