stabilize const_cell_into_inner
This commit is contained in:
parent
851f698682
commit
ac488a2c3f
@ -514,7 +514,8 @@ pub fn replace(&self, val: T) -> T {
|
|||||||
/// assert_eq!(five, 5);
|
/// assert_eq!(five, 5);
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "move_cell", since = "1.17.0")]
|
#[stable(feature = "move_cell", since = "1.17.0")]
|
||||||
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
|
#[rustc_const_stable(feature = "const_cell_into_inner", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
|
||||||
pub const fn into_inner(self) -> T {
|
pub const fn into_inner(self) -> T {
|
||||||
self.value.into_inner()
|
self.value.into_inner()
|
||||||
}
|
}
|
||||||
@ -857,7 +858,8 @@ pub const fn new(value: T) -> RefCell<T> {
|
|||||||
/// let five = c.into_inner();
|
/// let five = c.into_inner();
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
|
#[rustc_const_stable(feature = "const_cell_into_inner", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn into_inner(self) -> T {
|
pub const fn into_inner(self) -> T {
|
||||||
// Since this function takes `self` (the `RefCell`) by value, the
|
// Since this function takes `self` (the `RefCell`) by value, the
|
||||||
@ -2098,8 +2100,8 @@ pub const fn new(value: T) -> UnsafeCell<T> {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
// When this is const stabilized, please remove `primitive_into_inner` below.
|
#[rustc_const_stable(feature = "const_cell_into_inner", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
|
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
|
||||||
pub const fn into_inner(self) -> T {
|
pub const fn into_inner(self) -> T {
|
||||||
self.value
|
self.value
|
||||||
}
|
}
|
||||||
@ -2245,47 +2247,6 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
|
|||||||
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
|
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
|
||||||
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
|
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
|
||||||
|
|
||||||
// Special cases of UnsafeCell::into_inner where T is a primitive. These are
|
|
||||||
// used by Atomic*::into_inner.
|
|
||||||
//
|
|
||||||
// The real UnsafeCell::into_inner cannot be used yet in a stable const function.
|
|
||||||
// That is blocked on a "precise drop analysis" unstable const feature.
|
|
||||||
// https://github.com/rust-lang/rust/issues/73255
|
|
||||||
macro_rules! unsafe_cell_primitive_into_inner {
|
|
||||||
($($primitive:ident $atomic:literal)*) => {
|
|
||||||
$(
|
|
||||||
#[cfg(target_has_atomic_load_store = $atomic)]
|
|
||||||
impl UnsafeCell<$primitive> {
|
|
||||||
pub(crate) const fn primitive_into_inner(self) -> $primitive {
|
|
||||||
self.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)*
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe_cell_primitive_into_inner! {
|
|
||||||
i8 "8"
|
|
||||||
u8 "8"
|
|
||||||
i16 "16"
|
|
||||||
u16 "16"
|
|
||||||
i32 "32"
|
|
||||||
u32 "32"
|
|
||||||
i64 "64"
|
|
||||||
u64 "64"
|
|
||||||
i128 "128"
|
|
||||||
u128 "128"
|
|
||||||
isize "ptr"
|
|
||||||
usize "ptr"
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_has_atomic_load_store = "ptr")]
|
|
||||||
impl<T> UnsafeCell<*mut T> {
|
|
||||||
pub(crate) const fn primitive_into_inner(self) -> *mut T {
|
|
||||||
self.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// [`UnsafeCell`], but [`Sync`].
|
/// [`UnsafeCell`], but [`Sync`].
|
||||||
///
|
///
|
||||||
/// This is just an `UnsafeCell`, except it implements `Sync`
|
/// This is just an `UnsafeCell`, except it implements `Sync`
|
||||||
|
@ -309,7 +309,8 @@ fn try_init<F, E>(&self, f: F) -> Result<&T, E>
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "once_cell", since = "1.70.0")]
|
#[stable(feature = "once_cell", since = "1.70.0")]
|
||||||
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
|
#[rustc_const_stable(feature = "const_cell_into_inner", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
|
||||||
pub const fn into_inner(self) -> Option<T> {
|
pub const fn into_inner(self) -> Option<T> {
|
||||||
// Because `into_inner` takes `self` by value, the compiler statically verifies
|
// Because `into_inner` takes `self` by value, the compiler statically verifies
|
||||||
// that it is not currently borrowed. So it is safe to move out `Option<T>`.
|
// that it is not currently borrowed. So it is safe to move out `Option<T>`.
|
||||||
|
@ -118,7 +118,6 @@
|
|||||||
#![feature(const_array_into_iter_constructors)]
|
#![feature(const_array_into_iter_constructors)]
|
||||||
#![feature(const_bigint_helper_methods)]
|
#![feature(const_bigint_helper_methods)]
|
||||||
#![feature(const_black_box)]
|
#![feature(const_black_box)]
|
||||||
#![feature(const_cell_into_inner)]
|
|
||||||
#![feature(const_char_encode_utf16)]
|
#![feature(const_char_encode_utf16)]
|
||||||
#![feature(const_char_encode_utf8)]
|
#![feature(const_char_encode_utf8)]
|
||||||
#![feature(const_eval_select)]
|
#![feature(const_eval_select)]
|
||||||
|
@ -577,7 +577,7 @@ pub fn from_mut_slice(v: &mut [bool]) -> &mut [Self] {
|
|||||||
#[stable(feature = "atomic_access", since = "1.15.0")]
|
#[stable(feature = "atomic_access", since = "1.15.0")]
|
||||||
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0")]
|
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0")]
|
||||||
pub const fn into_inner(self) -> bool {
|
pub const fn into_inner(self) -> bool {
|
||||||
self.v.primitive_into_inner() != 0
|
self.v.into_inner() != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads a value from the bool.
|
/// Loads a value from the bool.
|
||||||
@ -1394,7 +1394,7 @@ pub fn from_mut_slice(v: &mut [*mut T]) -> &mut [Self] {
|
|||||||
#[stable(feature = "atomic_access", since = "1.15.0")]
|
#[stable(feature = "atomic_access", since = "1.15.0")]
|
||||||
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0")]
|
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0")]
|
||||||
pub const fn into_inner(self) -> *mut T {
|
pub const fn into_inner(self) -> *mut T {
|
||||||
self.p.primitive_into_inner()
|
self.p.into_inner()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads a value from the pointer.
|
/// Loads a value from the pointer.
|
||||||
@ -2389,7 +2389,7 @@ pub fn from_mut_slice(v: &mut [$int_type]) -> &mut [Self] {
|
|||||||
#[$stable_access]
|
#[$stable_access]
|
||||||
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0")]
|
#[rustc_const_stable(feature = "const_atomic_into_inner", since = "1.79.0")]
|
||||||
pub const fn into_inner(self) -> $int_type {
|
pub const fn into_inner(self) -> $int_type {
|
||||||
self.v.primitive_into_inner()
|
self.v.into_inner()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads a value from the atomic integer.
|
/// Loads a value from the atomic integer.
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#![feature(const_align_offset)]
|
#![feature(const_align_offset)]
|
||||||
#![feature(const_array_from_ref)]
|
#![feature(const_array_from_ref)]
|
||||||
#![feature(const_black_box)]
|
#![feature(const_black_box)]
|
||||||
#![feature(const_cell_into_inner)]
|
|
||||||
#![feature(const_hash)]
|
#![feature(const_hash)]
|
||||||
#![feature(const_heap)]
|
#![feature(const_heap)]
|
||||||
#![feature(const_ip)]
|
#![feature(const_ip)]
|
||||||
|
Loading…
Reference in New Issue
Block a user