2015-01-14 18:08:07 -06:00
|
|
|
use core::any::TypeId;
|
2020-09-24 09:41:40 -05:00
|
|
|
use core::intrinsics::assume;
|
2015-01-06 15:59:07 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_typeid_sized_types() {
|
2019-12-06 22:18:12 -06:00
|
|
|
struct X;
|
|
|
|
struct Y(u32);
|
2015-01-06 15:59:07 -06:00
|
|
|
|
|
|
|
assert_eq!(TypeId::of::<X>(), TypeId::of::<X>());
|
|
|
|
assert_eq!(TypeId::of::<Y>(), TypeId::of::<Y>());
|
|
|
|
assert!(TypeId::of::<X>() != TypeId::of::<Y>());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_typeid_unsized_types() {
|
|
|
|
trait Z {}
|
2019-12-06 22:18:12 -06:00
|
|
|
struct X(str);
|
|
|
|
struct Y(dyn Z + 'static);
|
2015-01-06 15:59:07 -06:00
|
|
|
|
|
|
|
assert_eq!(TypeId::of::<X>(), TypeId::of::<X>());
|
|
|
|
assert_eq!(TypeId::of::<Y>(), TypeId::of::<Y>());
|
|
|
|
assert!(TypeId::of::<X>() != TypeId::of::<Y>());
|
|
|
|
}
|
2020-09-24 09:41:40 -05:00
|
|
|
|
|
|
|
// Check that `const_assume` feature allow `assume` intrinsic
|
|
|
|
// to be used in const contexts.
|
|
|
|
#[test]
|
|
|
|
fn test_assume_can_be_in_const_contexts() {
|
|
|
|
const unsafe fn foo(x: usize, y: usize) -> usize {
|
|
|
|
// SAFETY: the entire function is not safe,
|
|
|
|
// but it is just an example not used elsewhere.
|
|
|
|
unsafe { assume(y != 0) };
|
|
|
|
x / y
|
|
|
|
}
|
|
|
|
let rs = unsafe { foo(42, 97) };
|
|
|
|
assert_eq!(rs, 0);
|
|
|
|
}
|