]>
git.proxmox.com Git - rustc.git/blob - vendor/derivative/tests/rustc-deriving-hash.rs
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.
11 #![allow(non_camel_case_types)]
13 #[cfg(feature = "use_core")]
17 extern crate derivative
;
19 use std
::hash
::{Hash, Hasher}
;
20 use std
::collections
::hash_map
::DefaultHasher
;
30 // test for hygiene name collisions
32 #[derivative(Hash)] struct __H__H;
34 #[allow(dead_code)] #[derivative(Hash)] struct Collision<__H> ( __H );
35 // TODO(rustc) #[derivative(Hash)] enum Collision<__H> { __H { __H__H: __H } }
41 fn hash
<T
: Hash
>(t
: &T
) -> u64 {
42 let mut s
= DefaultHasher
::new();
47 struct FakeHasher
<'a
>(&'a
mut Vec
<u8>);
48 impl<'a
> Hasher
for FakeHasher
<'a
> {
49 fn finish(&self) -> u64 {
53 fn write(&mut self, bytes
: &[u8]) {
58 fn fake_hash(v
: &mut Vec
<u8>, e
: E
) {
59 e
.hash(&mut FakeHasher(v
));
64 let person1
= Person
{
66 name
: "Janet".to_string(),
69 let person2
= Person
{
71 name
: "Bob".to_string(),
74 assert_eq
!(hash(&person1
), hash(&person1
));
75 assert
!(hash(&person1
) != hash(&person2
));
80 fake_hash(&mut va
, E
::A
);
81 fake_hash(&mut vb
, E
::B
);