Skip to content

Commit b8c2a2a

Browse files
committed
stabilize const_cell_into_inner
1 parent 3a00bff commit b8c2a2a

File tree

5 files changed

+11
-51
lines changed

5 files changed

+11
-51
lines changed

core/src/cell.rs

+6-45
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ impl<T> Cell<T> {
514514
/// assert_eq!(five, 5);
515515
/// ```
516516
#[stable(feature = "move_cell", since = "1.17.0")]
517-
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
517+
#[rustc_const_stable(feature = "const_cell_into_inner", since = "CURRENT_RUSTC_VERSION")]
518+
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
518519
pub const fn into_inner(self) -> T {
519520
self.value.into_inner()
520521
}
@@ -857,7 +858,8 @@ impl<T> RefCell<T> {
857858
/// let five = c.into_inner();
858859
/// ```
859860
#[stable(feature = "rust1", since = "1.0.0")]
860-
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
861+
#[rustc_const_stable(feature = "const_cell_into_inner", since = "CURRENT_RUSTC_VERSION")]
862+
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
861863
#[inline]
862864
pub const fn into_inner(self) -> T {
863865
// Since this function takes `self` (the `RefCell`) by value, the
@@ -2098,8 +2100,8 @@ impl<T> UnsafeCell<T> {
20982100
/// ```
20992101
#[inline(always)]
21002102
#[stable(feature = "rust1", since = "1.0.0")]
2101-
// When this is const stabilized, please remove `primitive_into_inner` below.
2102-
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
2103+
#[rustc_const_stable(feature = "const_cell_into_inner", since = "CURRENT_RUSTC_VERSION")]
2104+
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
21032105
pub const fn into_inner(self) -> T {
21042106
self.value
21052107
}
@@ -2245,47 +2247,6 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
22452247
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
22462248
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
22472249

2248-
// Special cases of UnsafeCell::into_inner where T is a primitive. These are
2249-
// used by Atomic*::into_inner.
2250-
//
2251-
// The real UnsafeCell::into_inner cannot be used yet in a stable const function.
2252-
// That is blocked on a "precise drop analysis" unstable const feature.
2253-
// https://github.com/rust-lang/rust/issues/73255
2254-
macro_rules! unsafe_cell_primitive_into_inner {
2255-
($($primitive:ident $atomic:literal)*) => {
2256-
$(
2257-
#[cfg(target_has_atomic_load_store = $atomic)]
2258-
impl UnsafeCell<$primitive> {
2259-
pub(crate) const fn primitive_into_inner(self) -> $primitive {
2260-
self.value
2261-
}
2262-
}
2263-
)*
2264-
};
2265-
}
2266-
2267-
unsafe_cell_primitive_into_inner! {
2268-
i8 "8"
2269-
u8 "8"
2270-
i16 "16"
2271-
u16 "16"
2272-
i32 "32"
2273-
u32 "32"
2274-
i64 "64"
2275-
u64 "64"
2276-
i128 "128"
2277-
u128 "128"
2278-
isize "ptr"
2279-
usize "ptr"
2280-
}
2281-
2282-
#[cfg(target_has_atomic_load_store = "ptr")]
2283-
impl<T> UnsafeCell<*mut T> {
2284-
pub(crate) const fn primitive_into_inner(self) -> *mut T {
2285-
self.value
2286-
}
2287-
}
2288-
22892250
/// [`UnsafeCell`], but [`Sync`].
22902251
///
22912252
/// This is just an `UnsafeCell`, except it implements `Sync`

core/src/cell/once.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ impl<T> OnceCell<T> {
309309
/// ```
310310
#[inline]
311311
#[stable(feature = "once_cell", since = "1.70.0")]
312-
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
312+
#[rustc_const_stable(feature = "const_cell_into_inner", since = "CURRENT_RUSTC_VERSION")]
313+
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
313314
pub const fn into_inner(self) -> Option<T> {
314315
// Because `into_inner` takes `self` by value, the compiler statically verifies
315316
// that it is not currently borrowed. So it is safe to move out `Option<T>`.

core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
#![feature(const_array_into_iter_constructors)]
119119
#![feature(const_bigint_helper_methods)]
120120
#![feature(const_black_box)]
121-
#![feature(const_cell_into_inner)]
122121
#![feature(const_char_encode_utf16)]
123122
#![feature(const_char_encode_utf8)]
124123
#![feature(const_eval_select)]

core/src/sync/atomic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ impl AtomicBool {
577577
#[stable(feature = "atomic_access", since = "1.15.0")]
578578
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0")]
579579
pub const fn into_inner(self) -> bool {
580-
self.v.primitive_into_inner() != 0
580+
self.v.into_inner() != 0
581581
}
582582

583583
/// Loads a value from the bool.
@@ -1394,7 +1394,7 @@ impl<T> AtomicPtr<T> {
13941394
#[stable(feature = "atomic_access", since = "1.15.0")]
13951395
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0")]
13961396
pub const fn into_inner(self) -> *mut T {
1397-
self.p.primitive_into_inner()
1397+
self.p.into_inner()
13981398
}
13991399

14001400
/// Loads a value from the pointer.
@@ -2389,7 +2389,7 @@ macro_rules! atomic_int {
23892389
#[$stable_access]
23902390
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0")]
23912391
pub const fn into_inner(self) -> $int_type {
2392-
self.v.primitive_into_inner()
2392+
self.v.into_inner()
23932393
}
23942394

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

core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#![feature(const_align_offset)]
1919
#![feature(const_array_from_ref)]
2020
#![feature(const_black_box)]
21-
#![feature(const_cell_into_inner)]
2221
#![feature(const_hash)]
2322
#![feature(const_heap)]
2423
#![feature(const_ip)]

0 commit comments

Comments
 (0)