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_name)]
10 use std::any::{self, TypeId};
12 pub struct GetTypeId<T>(T);
14 impl<T: 'static> GetTypeId<T> {
15 pub const VALUE: TypeId = TypeId::of::<T>();
18 const fn check_type_id<T: 'static>() -> bool {
19 matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
20 //~^ ERROR constant pattern depends on a generic parameter
21 //~| ERROR constant pattern depends on a generic parameter
24 pub struct GetTypeNameLen<T>(T);
26 impl<T: 'static> GetTypeNameLen<T> {
27 pub const VALUE: usize = any::type_name::<T>().len();
30 const fn check_type_name_len<T: 'static>() -> bool {
31 matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE)
32 //~^ ERROR constant pattern depends on a generic parameter
33 //~| ERROR constant pattern depends on a generic parameter
37 assert!(check_type_id::<usize>());
38 assert!(check_type_name_len::<usize>());