]> git.lizzy.rs Git - rust.git/blob - library/core/tests/intrinsics.rs
Rollup merge of #85912 - LingMan:iter_any, r=nagisa
[rust.git] / library / core / tests / intrinsics.rs
1 use core::any::TypeId;
2 use core::intrinsics::assume;
3
4 #[test]
5 fn test_typeid_sized_types() {
6     struct X;
7     struct Y(u32);
8
9     assert_eq!(TypeId::of::<X>(), TypeId::of::<X>());
10     assert_eq!(TypeId::of::<Y>(), TypeId::of::<Y>());
11     assert!(TypeId::of::<X>() != TypeId::of::<Y>());
12 }
13
14 #[test]
15 fn test_typeid_unsized_types() {
16     trait Z {}
17     struct X(str);
18     struct Y(dyn Z + 'static);
19
20     assert_eq!(TypeId::of::<X>(), TypeId::of::<X>());
21     assert_eq!(TypeId::of::<Y>(), TypeId::of::<Y>());
22     assert!(TypeId::of::<X>() != TypeId::of::<Y>());
23 }
24
25 // Check that `const_assume` feature allow `assume` intrinsic
26 // to be used in const contexts.
27 #[test]
28 fn test_assume_can_be_in_const_contexts() {
29     const unsafe fn foo(x: usize, y: usize) -> usize {
30         // SAFETY: the entire function is not safe,
31         // but it is just an example not used elsewhere.
32         unsafe { assume(y != 0) };
33         x / y
34     }
35     let rs = unsafe { foo(42, 97) };
36     assert_eq!(rs, 0);
37 }