Skip to content

Commit ff88a9a

Browse files
committed
Stabilize const Atomic*::into_inner
1 parent 9d79cd5 commit ff88a9a

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

library/core/src/cell.rs

+42
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,7 @@ impl<T> UnsafeCell<T> {
20712071
/// ```
20722072
#[inline(always)]
20732073
#[stable(feature = "rust1", since = "1.0.0")]
2074+
// When this is const stabilized, please remove `primitive_into_inner` below.
20742075
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
20752076
pub const fn into_inner(self) -> T {
20762077
self.value
@@ -2217,6 +2218,47 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
22172218
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
22182219
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
22192220

2221+
// Special cases of UnsafeCell::into_inner where T is a primitive. These are
2222+
// used by Atomic*::into_inner.
2223+
//
2224+
// The real UnsafeCell::into_inner cannot be used yet in a stable const function.
2225+
// That is blocked on a "precise drop analysis" unstable const feature.
2226+
// https://github.com/rust-lang/rust/issues/73255
2227+
macro_rules! unsafe_cell_primitive_into_inner {
2228+
($($primitive:ident $atomic:literal)*) => {
2229+
$(
2230+
#[cfg(target_has_atomic_load_store = $atomic)]
2231+
impl UnsafeCell<$primitive> {
2232+
pub(crate) const fn primitive_into_inner(self) -> $primitive {
2233+
self.value
2234+
}
2235+
}
2236+
)*
2237+
};
2238+
}
2239+
2240+
unsafe_cell_primitive_into_inner! {
2241+
i8 "8"
2242+
u8 "8"
2243+
i16 "16"
2244+
u16 "16"
2245+
i32 "32"
2246+
u32 "32"
2247+
i64 "64"
2248+
u64 "64"
2249+
i128 "128"
2250+
u128 "128"
2251+
isize "ptr"
2252+
usize "ptr"
2253+
}
2254+
2255+
#[cfg(target_has_atomic_load_store = "ptr")]
2256+
impl<T> UnsafeCell<*mut T> {
2257+
pub(crate) const fn primitive_into_inner(self) -> *mut T {
2258+
self.value
2259+
}
2260+
}
2261+
22202262
/// [`UnsafeCell`], but [`Sync`].
22212263
///
22222264
/// This is just an `UnsafeCell`, except it implements `Sync`

library/core/src/sync/atomic.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,9 @@ impl AtomicBool {
578578
/// ```
579579
#[inline]
580580
#[stable(feature = "atomic_access", since = "1.15.0")]
581-
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
581+
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "CURRENT_RUSTC_VERSION")]
582582
pub const fn into_inner(self) -> bool {
583-
self.v.into_inner() != 0
583+
self.v.primitive_into_inner() != 0
584584
}
585585

586586
/// Loads a value from the bool.
@@ -1397,9 +1397,9 @@ impl<T> AtomicPtr<T> {
13971397
/// ```
13981398
#[inline]
13991399
#[stable(feature = "atomic_access", since = "1.15.0")]
1400-
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
1400+
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "CURRENT_RUSTC_VERSION")]
14011401
pub const fn into_inner(self) -> *mut T {
1402-
self.p.into_inner()
1402+
self.p.primitive_into_inner()
14031403
}
14041404

14051405
/// Loads a value from the pointer.
@@ -2378,9 +2378,9 @@ macro_rules! atomic_int {
23782378
/// ```
23792379
#[inline]
23802380
#[$stable_access]
2381-
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
2381+
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "CURRENT_RUSTC_VERSION")]
23822382
pub const fn into_inner(self) -> $int_type {
2383-
self.v.into_inner()
2383+
self.v.primitive_into_inner()
23842384
}
23852385

23862386
/// Loads a value from the atomic integer.

0 commit comments

Comments
 (0)