]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2013-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. | |
4 | // | |
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. | |
10 | ||
54a0048b SL |
11 | // aux-build:typeid-intrinsic-aux1.rs |
12 | // aux-build:typeid-intrinsic-aux2.rs | |
1a4d82fc | 13 | |
e9174d1e | 14 | #![feature(core_intrinsics)] |
c34b1796 | 15 | |
54a0048b SL |
16 | extern crate typeid_intrinsic_aux1 as other1; |
17 | extern crate typeid_intrinsic_aux2 as other2; | |
1a4d82fc | 18 | |
e9174d1e | 19 | use std::hash::{SipHasher, Hasher, Hash}; |
85aaf69f | 20 | use std::any::TypeId; |
1a4d82fc JJ |
21 | |
22 | struct A; | |
23 | struct Test; | |
24 | ||
25 | pub fn main() { | |
26 | unsafe { | |
85aaf69f SL |
27 | assert_eq!(TypeId::of::<other1::A>(), other1::id_A()); |
28 | assert_eq!(TypeId::of::<other1::B>(), other1::id_B()); | |
29 | assert_eq!(TypeId::of::<other1::C>(), other1::id_C()); | |
30 | assert_eq!(TypeId::of::<other1::D>(), other1::id_D()); | |
31 | assert_eq!(TypeId::of::<other1::E>(), other1::id_E()); | |
32 | assert_eq!(TypeId::of::<other1::F>(), other1::id_F()); | |
33 | assert_eq!(TypeId::of::<other1::G>(), other1::id_G()); | |
34 | assert_eq!(TypeId::of::<other1::H>(), other1::id_H()); | |
1a4d82fc | 35 | |
85aaf69f SL |
36 | assert_eq!(TypeId::of::<other2::A>(), other2::id_A()); |
37 | assert_eq!(TypeId::of::<other2::B>(), other2::id_B()); | |
38 | assert_eq!(TypeId::of::<other2::C>(), other2::id_C()); | |
39 | assert_eq!(TypeId::of::<other2::D>(), other2::id_D()); | |
40 | assert_eq!(TypeId::of::<other2::E>(), other2::id_E()); | |
41 | assert_eq!(TypeId::of::<other2::F>(), other2::id_F()); | |
42 | assert_eq!(TypeId::of::<other2::G>(), other2::id_G()); | |
43 | assert_eq!(TypeId::of::<other2::H>(), other2::id_H()); | |
1a4d82fc JJ |
44 | |
45 | assert_eq!(other1::id_F(), other2::id_F()); | |
46 | assert_eq!(other1::id_G(), other2::id_G()); | |
47 | assert_eq!(other1::id_H(), other2::id_H()); | |
48 | ||
c34b1796 AL |
49 | assert_eq!(TypeId::of::<isize>(), other2::foo::<isize>()); |
50 | assert_eq!(TypeId::of::<isize>(), other1::foo::<isize>()); | |
51 | assert_eq!(other2::foo::<isize>(), other1::foo::<isize>()); | |
85aaf69f SL |
52 | assert_eq!(TypeId::of::<A>(), other2::foo::<A>()); |
53 | assert_eq!(TypeId::of::<A>(), other1::foo::<A>()); | |
1a4d82fc JJ |
54 | assert_eq!(other2::foo::<A>(), other1::foo::<A>()); |
55 | } | |
56 | ||
57 | // sanity test of TypeId | |
c34b1796 | 58 | let (a, b, c) = (TypeId::of::<usize>(), TypeId::of::<&'static str>(), |
1a4d82fc | 59 | TypeId::of::<Test>()); |
c34b1796 | 60 | let (d, e, f) = (TypeId::of::<usize>(), TypeId::of::<&'static str>(), |
1a4d82fc JJ |
61 | TypeId::of::<Test>()); |
62 | ||
63 | assert!(a != b); | |
64 | assert!(a != c); | |
65 | assert!(b != c); | |
66 | ||
67 | assert_eq!(a, d); | |
68 | assert_eq!(b, e); | |
69 | assert_eq!(c, f); | |
70 | ||
71 | // check it has a hash | |
c34b1796 | 72 | let (a, b) = (TypeId::of::<usize>(), TypeId::of::<usize>()); |
1a4d82fc | 73 | |
e9174d1e SL |
74 | let mut s1 = SipHasher::new(); |
75 | a.hash(&mut s1); | |
76 | let mut s2 = SipHasher::new(); | |
77 | b.hash(&mut s2); | |
78 | ||
79 | assert_eq!(s1.finish(), s2.finish()); | |
1a4d82fc | 80 | } |