@@ -673,39 +673,57 @@ mod impls {
673
673
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
674
674
impl < T : ?Sized > Hash for * const T {
675
675
fn hash < H : Hasher > ( & self , state : & mut H ) {
676
- if mem:: size_of :: < Self > ( ) == mem:: size_of :: < usize > ( ) {
677
- // Thin pointer
678
- state. write_usize ( * self as * const ( ) as usize ) ;
679
- } else {
680
- // Fat pointer
681
- // SAFETY: we are accessing the memory occupied by `self`
682
- // which is guaranteed to be valid.
683
- // This assumes a fat pointer can be represented by a `(usize, usize)`,
684
- // which is safe to do in `std` because it is shipped and kept in sync
685
- // with the implementation of fat pointers in `rustc`.
686
- let ( a, b) = unsafe { * ( self as * const Self as * const ( usize , usize ) ) } ;
687
- state. write_usize ( a) ;
688
- state. write_usize ( b) ;
676
+ #[ cfg( not( bootstrap) ) ]
677
+ {
678
+ let ( address, metadata) = self . to_raw_parts ( ) ;
679
+ state. write_usize ( address as usize ) ;
680
+ metadata. hash ( state) ;
681
+ }
682
+ #[ cfg( bootstrap) ]
683
+ {
684
+ if mem:: size_of :: < Self > ( ) == mem:: size_of :: < usize > ( ) {
685
+ // Thin pointer
686
+ state. write_usize ( * self as * const ( ) as usize ) ;
687
+ } else {
688
+ // Fat pointer
689
+ // SAFETY: we are accessing the memory occupied by `self`
690
+ // which is guaranteed to be valid.
691
+ // This assumes a fat pointer can be represented by a `(usize, usize)`,
692
+ // which is safe to do in `std` because it is shipped and kept in sync
693
+ // with the implementation of fat pointers in `rustc`.
694
+ let ( a, b) = unsafe { * ( self as * const Self as * const ( usize , usize ) ) } ;
695
+ state. write_usize ( a) ;
696
+ state. write_usize ( b) ;
697
+ }
689
698
}
690
699
}
691
700
}
692
701
693
702
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
694
703
impl < T : ?Sized > Hash for * mut T {
695
704
fn hash < H : Hasher > ( & self , state : & mut H ) {
696
- if mem:: size_of :: < Self > ( ) == mem:: size_of :: < usize > ( ) {
697
- // Thin pointer
698
- state. write_usize ( * self as * const ( ) as usize ) ;
699
- } else {
700
- // Fat pointer
701
- // SAFETY: we are accessing the memory occupied by `self`
702
- // which is guaranteed to be valid.
703
- // This assumes a fat pointer can be represented by a `(usize, usize)`,
704
- // which is safe to do in `std` because it is shipped and kept in sync
705
- // with the implementation of fat pointers in `rustc`.
706
- let ( a, b) = unsafe { * ( self as * const Self as * const ( usize , usize ) ) } ;
707
- state. write_usize ( a) ;
708
- state. write_usize ( b) ;
705
+ #[ cfg( not( bootstrap) ) ]
706
+ {
707
+ let ( address, metadata) = self . to_raw_parts ( ) ;
708
+ state. write_usize ( address as usize ) ;
709
+ metadata. hash ( state) ;
710
+ }
711
+ #[ cfg( bootstrap) ]
712
+ {
713
+ if mem:: size_of :: < Self > ( ) == mem:: size_of :: < usize > ( ) {
714
+ // Thin pointer
715
+ state. write_usize ( * self as * const ( ) as usize ) ;
716
+ } else {
717
+ // Fat pointer
718
+ // SAFETY: we are accessing the memory occupied by `self`
719
+ // which is guaranteed to be valid.
720
+ // This assumes a fat pointer can be represented by a `(usize, usize)`,
721
+ // which is safe to do in `std` because it is shipped and kept in sync
722
+ // with the implementation of fat pointers in `rustc`.
723
+ let ( a, b) = unsafe { * ( self as * const Self as * const ( usize , usize ) ) } ;
724
+ state. write_usize ( a) ;
725
+ state. write_usize ( b) ;
726
+ }
709
727
}
710
728
}
711
729
}
0 commit comments