Skip to content

Commit a694315

Browse files
Add a note about fat pointers
Co-Authored-By: Mark-Simulacrum <mark.simulacrum@gmail.com>
1 parent 3029e9e commit a694315

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/libcore/hash/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ mod impls {
695695
// Fat pointer
696696
// SAFETY: we are accessing the memory occupied by `self`
697697
// which is guaranteed to be valid.
698+
// This assumes a fat pointer can be represented by a `(usize, usize)`,
699+
// which is safe to do in `std` because it is shipped and kept in sync
700+
// with the implementation of fat pointers in `rustc`.
698701
let (a, b) = unsafe { *(self as *const Self as *const (usize, usize)) };
699702
state.write_usize(a);
700703
state.write_usize(b);
@@ -712,6 +715,9 @@ mod impls {
712715
// Fat pointer
713716
// SAFETY: we are accessing the memory occupied by `self`
714717
// which is guaranteed to be valid.
718+
// This assumes a fat pointer can be represented by a `(usize, usize)`,
719+
// which is safe to do in `std` because it is shipped and kept in sync
720+
// with the implementation of fat pointers in `rustc`.
715721
let (a, b) = unsafe { *(self as *const Self as *const (usize, usize)) };
716722
state.write_usize(a);
717723
state.write_usize(b);

0 commit comments

Comments
 (0)