@@ -711,14 +711,23 @@ pub struct TypeId {
711
711
/// Quick accept: if pointers are the same, the ids are the same
712
712
data : & ' static TypeIdData ,
713
713
/// 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 ( ) ,
715
719
}
716
720
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
+
717
728
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
718
729
struct TypeIdData {
719
730
full_hash : [ u8 ; 16 ] ,
720
- #[ cfg( feature = "debug_typeid" ) ]
721
- name : & ' static str ,
722
731
}
723
732
724
733
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -759,15 +768,13 @@ impl TypeId {
759
768
pub const fn of < T : ?Sized + ' static > ( ) -> TypeId {
760
769
let data = & const {
761
770
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 ( ) }
768
772
} ;
769
773
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
+ }
771
778
}
772
779
773
780
fn as_u128 ( self ) -> u128 {
@@ -803,15 +810,7 @@ impl hash::Hash for TypeId {
803
810
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
804
811
impl fmt:: Debug for TypeId {
805
812
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> Result < ( ) , fmt:: Error > {
806
- #[ cfg( feature = "debug_typeid" ) ]
807
- {
808
- write ! ( f, "TypeId({:#034x} = {})" , self . as_u128( ) , self . name) ?;
809
- }
810
- #[ cfg( not( feature = "debug_typeid" ) ) ]
811
- {
812
- write ! ( f, "TypeId({:#034x})" , self . as_u128( ) ) ?;
813
- }
814
- Ok ( ( ) )
813
+ write ! ( f, "TypeId({:#034x})" , self . as_u128( ) )
815
814
}
816
815
}
817
816
0 commit comments