Skip to content

Commit

Permalink
Unrolled build for rust-lang#131261
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#131261 - clarfonthey:unsafe-cell-from-mut, r=m-ou-se

Stabilize `UnsafeCell::from_mut`

Closes rust-lang#111645.
FCP: rust-lang#111645 (comment)

Note that because `const_mut_refs` and `const_refs_to_cell` was stabilized, it's okay to const-stabilize this method as well.
  • Loading branch information
rust-timer authored Nov 6, 2024
2 parents 4a91ff6 + 6828a1e commit 54e2ce7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,6 @@ impl<T: ?Sized> UnsafeCell<T> {
/// # Examples
///
/// ```
/// # #![feature(unsafe_cell_from_mut)]
/// use std::cell::UnsafeCell;
///
/// let mut val = 42;
Expand All @@ -2132,7 +2131,9 @@ impl<T: ?Sized> UnsafeCell<T> {
/// assert_eq!(*uc.get_mut(), 41);
/// ```
#[inline(always)]
#[unstable(feature = "unsafe_cell_from_mut", issue = "111645")]
#[stable(feature = "unsafe_cell_from_mut", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "unsafe_cell_from_mut", since = "CURRENT_RUSTC_VERSION")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
pub const fn from_mut(value: &mut T) -> &mut UnsafeCell<T> {
// SAFETY: `UnsafeCell<T>` has the same memory layout as `T` due to #[repr(transparent)].
unsafe { &mut *(value as *mut T as *mut UnsafeCell<T>) }
Expand Down

0 comments on commit 54e2ce7

Please sign in to comment.