From a694315ed1943496149980dd80a0da2b1d71ff1c Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 23 Apr 2020 23:05:37 +0200 Subject: [PATCH] Add a note about fat pointers Co-Authored-By: Mark-Simulacrum --- src/libcore/hash/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 4f66b00b2796b..d80101753cbef 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -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); @@ -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);