79
79
//! }
80
80
//! ```
81
81
82
- // ignore-tidy-undocumented-unsafe
83
-
84
82
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
85
83
86
84
use crate :: fmt;
@@ -572,6 +570,9 @@ mod impls {
572
570
fn hash_slice<H : Hasher >( data: & [ $ty] , state: & mut H ) {
573
571
let newlen = data. len( ) * mem:: size_of:: <$ty>( ) ;
574
572
let ptr = data. as_ptr( ) as * const u8 ;
573
+ // SAFETY: `ptr` is valid and aligned, the new slice only spans
574
+ // across `data` and is never mutated, and its total size is the
575
+ // same as the original `data` so it can't be over `isize::MAX`.
575
576
state. write( unsafe { slice:: from_raw_parts( ptr, newlen) } )
576
577
}
577
578
}
@@ -691,6 +692,8 @@ mod impls {
691
692
state. write_usize ( * self as * const ( ) as usize ) ;
692
693
} else {
693
694
// Fat pointer
695
+ // SAFETY: we are accessing the memory occupied by `self`
696
+ // which is guaranteed to be valid.
694
697
let ( a, b) = unsafe { * ( self as * const Self as * const ( usize , usize ) ) } ;
695
698
state. write_usize ( a) ;
696
699
state. write_usize ( b) ;
@@ -706,6 +709,8 @@ mod impls {
706
709
state. write_usize ( * self as * const ( ) as usize ) ;
707
710
} else {
708
711
// Fat pointer
712
+ // SAFETY: we are accessing the memory occupied by `self`
713
+ // which is guaranteed to be valid.
709
714
let ( a, b) = unsafe { * ( self as * const Self as * const ( usize , usize ) ) } ;
710
715
state. write_usize ( a) ;
711
716
state. write_usize ( b) ;
0 commit comments