From 41434e001be222a7ce70faf3c5a23d97f462dfb8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 16 Nov 2018 22:17:26 +0100 Subject: [PATCH 1/2] avoid shared ref in UnsafeCell::get --- src/libcore/cell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 9cf42eff219..b1ef15b4513 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -1509,7 +1509,7 @@ impl UnsafeCell { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub const fn get(&self) -> *mut T { - &self.value as *const T as *mut T + self as *const UnsafeCell as *const T as *mut T } } From 25d46f309130be1671d7e44d48e67b23f510bcdc Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 17 Nov 2018 10:20:28 +0100 Subject: [PATCH 2/2] add comment explaining why what we do is legal --- src/libcore/cell.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index b1ef15b4513..d8d51f53377 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -1509,6 +1509,8 @@ impl UnsafeCell { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub const fn get(&self) -> *mut T { + // We can just cast the pointer from `UnsafeCell` to `T` because of + // #[repr(transparent)] self as *const UnsafeCell as *const T as *mut T } }