Skip to content

Commit 19ebe2f

Browse files
committed
clarify why we can do the ptr cast
1 parent aba385a commit 19ebe2f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/libcore/cell.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,8 @@ impl<T: ?Sized> UnsafeCell<T> {
15451545
#[stable(feature = "rust1", since = "1.0.0")]
15461546
pub const fn get(&self) -> *mut T {
15471547
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
1548-
// #[repr(transparent)]
1548+
// #[repr(transparent)]. This exploits libstd's special status, there is
1549+
// no guarantee for user code that this will work in future versions of the compiler!
15491550
self as *const UnsafeCell<T> as *const T as *mut T
15501551
}
15511552

@@ -1572,10 +1573,11 @@ impl<T: ?Sized> UnsafeCell<T> {
15721573
/// assert_eq!(uc.into_inner(), 5);
15731574
/// ```
15741575
#[inline]
1575-
#[unstable(feature = "unsafe_cell_raw_get", issue = "0")]
1576+
#[unstable(feature = "unsafe_cell_raw_get", issue = "66358")]
15761577
pub const fn raw_get(self: *const Self) -> *mut T {
15771578
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
1578-
// #[repr(transparent)]
1579+
// #[repr(transparent)]. This exploits libstd's special status, there is
1580+
// no guarantee for user code that this will work in future versions of the compiler!
15791581
self as *const T as *mut T
15801582
}
15811583
}

0 commit comments

Comments
 (0)