From 19ebe2fb6d7de19de155e70938fafcca6f9b5003 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 13 Nov 2019 09:07:52 +0100 Subject: [PATCH] clarify why we can do the ptr cast --- src/libcore/cell.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index e3292ecc1d1..4afeec66758 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -1545,7 +1545,8 @@ impl UnsafeCell { #[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)] + // #[repr(transparent)]. This exploits libstd's special status, there is + // no guarantee for user code that this will work in future versions of the compiler! self as *const UnsafeCell as *const T as *mut T } @@ -1572,10 +1573,11 @@ impl UnsafeCell { /// assert_eq!(uc.into_inner(), 5); /// ``` #[inline] - #[unstable(feature = "unsafe_cell_raw_get", issue = "0")] + #[unstable(feature = "unsafe_cell_raw_get", issue = "66358")] pub const fn raw_get(self: *const Self) -> *mut T { // We can just cast the pointer from `UnsafeCell` to `T` because of - // #[repr(transparent)] + // #[repr(transparent)]. This exploits libstd's special status, there is + // no guarantee for user code that this will work in future versions of the compiler! self as *const T as *mut T } }