make Cell unstably const
This commit is contained in:
parent
5a4ee43c38
commit
98aa3d96e2
@ -494,8 +494,9 @@ fn is_nonoverlapping<T>(src: *const T, dst: *const T) -> bool {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "move_cell", since = "1.17.0")]
|
#[stable(feature = "move_cell", since = "1.17.0")]
|
||||||
|
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
|
||||||
#[rustc_confusables("swap")]
|
#[rustc_confusables("swap")]
|
||||||
pub fn replace(&self, val: T) -> T {
|
pub const fn replace(&self, val: T) -> T {
|
||||||
// SAFETY: This can cause data races if called from a separate thread,
|
// SAFETY: This can cause data races if called from a separate thread,
|
||||||
// but `Cell` is `!Sync` so this won't happen.
|
// but `Cell` is `!Sync` so this won't happen.
|
||||||
mem::replace(unsafe { &mut *self.value.get() }, val)
|
mem::replace(unsafe { &mut *self.value.get() }, val)
|
||||||
@ -535,7 +536,8 @@ impl<T: Copy> Cell<T> {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn get(&self) -> T {
|
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
|
||||||
|
pub const fn get(&self) -> T {
|
||||||
// SAFETY: This can cause data races if called from a separate thread,
|
// SAFETY: This can cause data races if called from a separate thread,
|
||||||
// but `Cell` is `!Sync` so this won't happen.
|
// but `Cell` is `!Sync` so this won't happen.
|
||||||
unsafe { *self.value.get() }
|
unsafe { *self.value.get() }
|
||||||
@ -613,7 +615,8 @@ pub const fn as_ptr(&self) -> *mut T {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "cell_get_mut", since = "1.11.0")]
|
#[stable(feature = "cell_get_mut", since = "1.11.0")]
|
||||||
pub fn get_mut(&mut self) -> &mut T {
|
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
|
||||||
|
pub const fn get_mut(&mut self) -> &mut T {
|
||||||
self.value.get_mut()
|
self.value.get_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,7 +635,8 @@ pub fn get_mut(&mut self) -> &mut T {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "as_cell", since = "1.37.0")]
|
#[stable(feature = "as_cell", since = "1.37.0")]
|
||||||
pub fn from_mut(t: &mut T) -> &Cell<T> {
|
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
|
||||||
|
pub const fn from_mut(t: &mut T) -> &Cell<T> {
|
||||||
// SAFETY: `&mut` ensures unique access.
|
// SAFETY: `&mut` ensures unique access.
|
||||||
unsafe { &*(t as *mut T as *const Cell<T>) }
|
unsafe { &*(t as *mut T as *const Cell<T>) }
|
||||||
}
|
}
|
||||||
@ -686,7 +690,8 @@ impl<T> Cell<[T]> {
|
|||||||
/// assert_eq!(slice_cell.len(), 3);
|
/// assert_eq!(slice_cell.len(), 3);
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "as_cell", since = "1.37.0")]
|
#[stable(feature = "as_cell", since = "1.37.0")]
|
||||||
pub fn as_slice_of_cells(&self) -> &[Cell<T>] {
|
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
|
||||||
|
pub const fn as_slice_of_cells(&self) -> &[Cell<T>] {
|
||||||
// SAFETY: `Cell<T>` has the same memory layout as `T`.
|
// SAFETY: `Cell<T>` has the same memory layout as `T`.
|
||||||
unsafe { &*(self as *const Cell<[T]> as *const [Cell<T>]) }
|
unsafe { &*(self as *const Cell<[T]> as *const [Cell<T>]) }
|
||||||
}
|
}
|
||||||
@ -706,7 +711,8 @@ pub fn as_slice_of_cells(&self) -> &[Cell<T>] {
|
|||||||
/// let array_cell: &[Cell<i32>; 3] = cell_array.as_array_of_cells();
|
/// let array_cell: &[Cell<i32>; 3] = cell_array.as_array_of_cells();
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "as_array_of_cells", issue = "88248")]
|
#[unstable(feature = "as_array_of_cells", issue = "88248")]
|
||||||
pub fn as_array_of_cells(&self) -> &[Cell<T>; N] {
|
#[rustc_const_unstable(feature = "as_array_of_cells", issue = "88248")]
|
||||||
|
pub const fn as_array_of_cells(&self) -> &[Cell<T>; N] {
|
||||||
// SAFETY: `Cell<T>` has the same memory layout as `T`.
|
// SAFETY: `Cell<T>` has the same memory layout as `T`.
|
||||||
unsafe { &*(self as *const Cell<[T; N]> as *const [Cell<T>; N]) }
|
unsafe { &*(self as *const Cell<[T; N]> as *const [Cell<T>; N]) }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user