2019-07-26 21:54:25 +00:00
|
|
|
//@ run-pass
|
|
|
|
|
2018-09-14 10:20:28 +00:00
|
|
|
#![allow(deprecated)]
|
2016-02-14 18:01:44 +00:00
|
|
|
//@ aux-build:typeid-intrinsic-aux1.rs
|
|
|
|
//@ aux-build:typeid-intrinsic-aux2.rs
|
2013-10-30 23:32:33 +00:00
|
|
|
|
2015-08-12 00:27:05 +00:00
|
|
|
#![feature(core_intrinsics)]
|
2015-03-06 02:33:58 +00:00
|
|
|
|
2016-02-14 18:01:44 +00:00
|
|
|
extern crate typeid_intrinsic_aux1 as other1;
|
|
|
|
extern crate typeid_intrinsic_aux2 as other2;
|
2013-10-30 23:32:33 +00:00
|
|
|
|
2015-08-12 00:27:05 +00:00
|
|
|
use std::hash::{SipHasher, Hasher, Hash};
|
2015-01-15 00:08:07 +00:00
|
|
|
use std::any::TypeId;
|
2013-10-30 23:32:33 +00:00
|
|
|
|
|
|
|
struct A;
|
2013-11-27 22:51:11 +00:00
|
|
|
struct Test;
|
2013-10-30 23:32:33 +00:00
|
|
|
|
2014-01-03 23:30:54 +00:00
|
|
|
pub fn main() {
|
2016-08-05 21:50:13 +00:00
|
|
|
assert_eq!(TypeId::of::<other1::A>(), other1::id_A());
|
|
|
|
assert_eq!(TypeId::of::<other1::B>(), other1::id_B());
|
|
|
|
assert_eq!(TypeId::of::<other1::C>(), other1::id_C());
|
|
|
|
assert_eq!(TypeId::of::<other1::D>(), other1::id_D());
|
|
|
|
assert_eq!(TypeId::of::<other1::E>(), other1::id_E());
|
|
|
|
assert_eq!(TypeId::of::<other1::F>(), other1::id_F());
|
|
|
|
assert_eq!(TypeId::of::<other1::G>(), other1::id_G());
|
|
|
|
assert_eq!(TypeId::of::<other1::H>(), other1::id_H());
|
|
|
|
assert_eq!(TypeId::of::<other1::I>(), other1::id_I());
|
2013-10-30 23:32:33 +00:00
|
|
|
|
2016-08-05 21:50:13 +00:00
|
|
|
assert_eq!(TypeId::of::<other2::A>(), other2::id_A());
|
|
|
|
assert_eq!(TypeId::of::<other2::B>(), other2::id_B());
|
|
|
|
assert_eq!(TypeId::of::<other2::C>(), other2::id_C());
|
|
|
|
assert_eq!(TypeId::of::<other2::D>(), other2::id_D());
|
|
|
|
assert_eq!(TypeId::of::<other2::E>(), other2::id_E());
|
|
|
|
assert_eq!(TypeId::of::<other2::F>(), other2::id_F());
|
|
|
|
assert_eq!(TypeId::of::<other2::G>(), other2::id_G());
|
|
|
|
assert_eq!(TypeId::of::<other2::H>(), other2::id_H());
|
|
|
|
assert_eq!(TypeId::of::<other1::I>(), other2::id_I());
|
2013-10-30 23:32:33 +00:00
|
|
|
|
2016-08-05 21:50:13 +00:00
|
|
|
assert_eq!(other1::id_F(), other2::id_F());
|
|
|
|
assert_eq!(other1::id_G(), other2::id_G());
|
|
|
|
assert_eq!(other1::id_H(), other2::id_H());
|
|
|
|
assert_eq!(other1::id_I(), other2::id_I());
|
2013-10-30 23:32:33 +00:00
|
|
|
|
2016-08-05 21:50:13 +00:00
|
|
|
assert_eq!(TypeId::of::<isize>(), other2::foo::<isize>());
|
|
|
|
assert_eq!(TypeId::of::<isize>(), other1::foo::<isize>());
|
|
|
|
assert_eq!(other2::foo::<isize>(), other1::foo::<isize>());
|
|
|
|
assert_eq!(TypeId::of::<A>(), other2::foo::<A>());
|
|
|
|
assert_eq!(TypeId::of::<A>(), other1::foo::<A>());
|
|
|
|
assert_eq!(other2::foo::<A>(), other1::foo::<A>());
|
2013-11-27 22:51:11 +00:00
|
|
|
|
|
|
|
// sanity test of TypeId
|
2015-03-26 00:06:52 +00:00
|
|
|
let (a, b, c) = (TypeId::of::<usize>(), TypeId::of::<&'static str>(),
|
2013-11-27 22:51:11 +00:00
|
|
|
TypeId::of::<Test>());
|
2015-03-26 00:06:52 +00:00
|
|
|
let (d, e, f) = (TypeId::of::<usize>(), TypeId::of::<&'static str>(),
|
2013-11-27 22:51:11 +00:00
|
|
|
TypeId::of::<Test>());
|
|
|
|
|
|
|
|
assert!(a != b);
|
|
|
|
assert!(a != c);
|
|
|
|
assert!(b != c);
|
|
|
|
|
|
|
|
assert_eq!(a, d);
|
|
|
|
assert_eq!(b, e);
|
|
|
|
assert_eq!(c, f);
|
|
|
|
|
|
|
|
// check it has a hash
|
2015-03-26 00:06:52 +00:00
|
|
|
let (a, b) = (TypeId::of::<usize>(), TypeId::of::<usize>());
|
2013-11-27 22:51:11 +00:00
|
|
|
|
2015-08-12 00:27:05 +00:00
|
|
|
let mut s1 = SipHasher::new();
|
|
|
|
a.hash(&mut s1);
|
|
|
|
let mut s2 = SipHasher::new();
|
|
|
|
b.hash(&mut s2);
|
|
|
|
|
|
|
|
assert_eq!(s1.finish(), s2.finish());
|
2016-09-13 19:02:17 +00:00
|
|
|
|
|
|
|
// Check projections
|
|
|
|
|
|
|
|
assert_eq!(TypeId::of::<other1::I32Iterator>(), other1::id_i32_iterator());
|
|
|
|
assert_eq!(TypeId::of::<other1::U32Iterator>(), other1::id_u32_iterator());
|
|
|
|
assert_eq!(other1::id_i32_iterator(), other2::id_i32_iterator());
|
|
|
|
assert_eq!(other1::id_u32_iterator(), other2::id_u32_iterator());
|
2019-08-09 18:04:18 +00:00
|
|
|
assert_ne!(other1::id_i32_iterator(), other1::id_u32_iterator());
|
|
|
|
assert_ne!(TypeId::of::<other1::I32Iterator>(), TypeId::of::<other1::U32Iterator>());
|
2016-09-19 09:37:12 +00:00
|
|
|
|
|
|
|
// Check fn pointer against collisions
|
2019-08-09 18:04:18 +00:00
|
|
|
assert_ne!(
|
|
|
|
TypeId::of::<fn(fn(A) -> A) -> A>(),
|
|
|
|
TypeId::of::<fn(fn() -> A, A) -> A>()
|
|
|
|
);
|
|
|
|
assert_ne!(
|
|
|
|
TypeId::of::<for<'a> fn(&'a i32) -> &'a i32>(),
|
|
|
|
TypeId::of::<for<'a> fn(&'a i32) -> &'static i32>()
|
|
|
|
);
|
|
|
|
assert_ne!(
|
|
|
|
TypeId::of::<for<'a, 'b> fn(&'a i32, &'b i32) -> &'a i32>(),
|
|
|
|
TypeId::of::<for<'a, 'b> fn(&'b i32, &'a i32) -> &'a i32>()
|
|
|
|
);
|
2013-10-30 23:32:33 +00:00
|
|
|
}
|