]> git.lizzy.rs Git - rust.git/blob - tests/ui/consts/issue-73976-monomorphic.rs
Rollup merge of #107023 - scottmcm:stop-shouting, r=Nilstrieb
[rust.git] / tests / ui / consts / issue-73976-monomorphic.rs
1 // check-pass
2 //
3 // This test is complement to the test in issue-73976-polymorphic.rs.
4 // In that test we ensure that polymorphic use of type_id and type_name in patterns
5 // will be properly rejected. This test will ensure that monomorphic use of these
6 // would not be wrongly rejected in patterns.
7
8 #![feature(const_type_id)]
9 #![feature(const_type_name)]
10 #![feature(const_trait_impl)]
11
12 use std::any::{self, TypeId};
13
14 pub struct GetTypeId<T>(T);
15
16 impl<T: 'static> GetTypeId<T> {
17     pub const VALUE: TypeId = TypeId::of::<T>();
18 }
19
20 const fn check_type_id<T: 'static>() -> bool {
21     GetTypeId::<T>::VALUE == GetTypeId::<usize>::VALUE
22 }
23
24 pub struct GetTypeNameLen<T>(T);
25
26 impl<T: 'static> GetTypeNameLen<T> {
27     pub const VALUE: usize = any::type_name::<T>().len();
28 }
29
30 const fn check_type_name_len<T: 'static>() -> bool {
31     matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<usize>::VALUE)
32 }
33
34 fn main() {
35     assert!(check_type_id::<usize>());
36     assert!(check_type_name_len::<usize>());
37 }