@@ -711,14 +711,23 @@ pub struct TypeId {
711711 /// Quick accept: if pointers are the same, the ids are the same
712712 data : & ' static TypeIdData ,
713713 /// Quick reject: if hashes are different, the ids are different
714- partial_hash : usize ,
714+ /// We use a raw pointer instead of a `usize`, because const eval
715+ /// will be storing this as a fake pointer that will turn into the
716+ /// appropriate bits at codegen time. This prevents users from inspecting
717+ /// these bits at compile time.
718+ partial_hash : * const ( ) ,
715719}
716720
721+ // SAFETY: the raw pointer is always an integer
722+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
723+ unsafe impl Send for TypeId { }
724+ // SAFETY: the raw pointer is always an integer
725+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
726+ unsafe impl Sync for TypeId { }
727+
717728#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
718729struct TypeIdData {
719730 full_hash : [ u8 ; 16 ] ,
720- #[ cfg( feature = "debug_typeid" ) ]
721- name : & ' static str ,
722731}
723732
724733#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -759,15 +768,13 @@ impl TypeId {
759768 pub const fn of < T : ?Sized + ' static > ( ) -> TypeId {
760769 let data = & const {
761770 let t: u128 = intrinsics:: type_id :: < T > ( ) ;
762- TypeIdData {
763- full_hash : t. to_ne_bytes ( ) ,
764-
765- #[ cfg( feature = "debug_typeid" ) ]
766- name : type_name :: < T > ( ) ,
767- }
771+ TypeIdData { full_hash : t. to_ne_bytes ( ) }
768772 } ;
769773
770- TypeId { data, partial_hash : intrinsics:: type_id :: < T > ( ) as usize }
774+ TypeId {
775+ data,
776+ partial_hash : crate :: ptr:: without_provenance ( intrinsics:: type_id :: < T > ( ) as usize ) ,
777+ }
771778 }
772779
773780 fn as_u128 ( self ) -> u128 {
@@ -798,15 +805,7 @@ impl hash::Hash for TypeId {
798805#[ stable( feature = "rust1" , since = "1.0.0" ) ]
799806impl fmt:: Debug for TypeId {
800807 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> Result < ( ) , fmt:: Error > {
801- #[ cfg( feature = "debug_typeid" ) ]
802- {
803- write ! ( f, "TypeId({:#034x} = {})" , self . as_u128( ) , self . name) ?;
804- }
805- #[ cfg( not( feature = "debug_typeid" ) ) ]
806- {
807- write ! ( f, "TypeId({:#034x})" , self . as_u128( ) ) ?;
808- }
809- Ok ( ( ) )
808+ write ! ( f, "TypeId({:#034x})" , self . as_u128( ) )
810809 }
811810}
812811
0 commit comments