1 // This test is from #73976. We previously did not check if a type is monomorphized
2 // before calculating its type id, which leads to the bizarre behaviour below that
3 // TypeId of a generic type does not match itself.
5 // This test case should either run-pass or be rejected at compile time.
6 // Currently we just disallow this usage and require pattern is monomorphic.
8 #![feature(const_type_id)]
9 #![feature(const_type_name)]
11 use std::any::{self, TypeId};
13 pub struct GetTypeId<T>(T);
15 impl<T: 'static> GetTypeId<T> {
16 pub const VALUE: TypeId = TypeId::of::<T>();
19 const fn check_type_id<T: 'static>() -> bool {
20 matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
21 //~^ ERROR constant pattern depends on a generic parameter
22 //~| ERROR constant pattern depends on a generic parameter
25 pub struct GetTypeNameLen<T>(T);
27 impl<T: 'static> GetTypeNameLen<T> {
28 pub const VALUE: usize = any::type_name::<T>().len();
31 const fn check_type_name_len<T: 'static>() -> bool {
32 matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE)
33 //~^ ERROR constant pattern depends on a generic parameter
34 //~| ERROR constant pattern depends on a generic parameter
38 assert!(check_type_id::<usize>());
39 assert!(check_type_name_len::<usize>());