Skip to content

Commit

Permalink
Add a note about fat pointers
Browse files Browse the repository at this point in the history
Co-Authored-By: Mark-Simulacrum <mark.simulacrum@gmail.com>
  • Loading branch information
LeSeulArtichaut and Mark-Simulacrum committed Apr 23, 2020
1 parent 3029e9e commit a694315
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ mod impls {
// Fat pointer
// SAFETY: we are accessing the memory occupied by `self`
// which is guaranteed to be valid.
// This assumes a fat pointer can be represented by a `(usize, usize)`,
// which is safe to do in `std` because it is shipped and kept in sync
// with the implementation of fat pointers in `rustc`.
let (a, b) = unsafe { *(self as *const Self as *const (usize, usize)) };
state.write_usize(a);
state.write_usize(b);
Expand All @@ -712,6 +715,9 @@ mod impls {
// Fat pointer
// SAFETY: we are accessing the memory occupied by `self`
// which is guaranteed to be valid.
// This assumes a fat pointer can be represented by a `(usize, usize)`,
// which is safe to do in `std` because it is shipped and kept in sync
// with the implementation of fat pointers in `rustc`.
let (a, b) = unsafe { *(self as *const Self as *const (usize, usize)) };
state.write_usize(a);
state.write_usize(b);
Expand Down

0 comments on commit a694315

Please sign in to comment.