Skip to content

Commit 2ed6282

Browse files
committed
make Cell unstably const
1 parent bbe8bf7 commit 2ed6282

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

core/src/cell.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,9 @@ impl<T> Cell<T> {
494494
/// ```
495495
#[inline]
496496
#[stable(feature = "move_cell", since = "1.17.0")]
497+
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
497498
#[rustc_confusables("swap")]
498-
pub fn replace(&self, val: T) -> T {
499+
pub const fn replace(&self, val: T) -> T {
499500
// SAFETY: This can cause data races if called from a separate thread,
500501
// but `Cell` is `!Sync` so this won't happen.
501502
mem::replace(unsafe { &mut *self.value.get() }, val)
@@ -535,7 +536,8 @@ impl<T: Copy> Cell<T> {
535536
/// ```
536537
#[inline]
537538
#[stable(feature = "rust1", since = "1.0.0")]
538-
pub fn get(&self) -> T {
539+
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
540+
pub const fn get(&self) -> T {
539541
// SAFETY: This can cause data races if called from a separate thread,
540542
// but `Cell` is `!Sync` so this won't happen.
541543
unsafe { *self.value.get() }
@@ -613,7 +615,8 @@ impl<T: ?Sized> Cell<T> {
613615
/// ```
614616
#[inline]
615617
#[stable(feature = "cell_get_mut", since = "1.11.0")]
616-
pub fn get_mut(&mut self) -> &mut T {
618+
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
619+
pub const fn get_mut(&mut self) -> &mut T {
617620
self.value.get_mut()
618621
}
619622

@@ -632,7 +635,8 @@ impl<T: ?Sized> Cell<T> {
632635
/// ```
633636
#[inline]
634637
#[stable(feature = "as_cell", since = "1.37.0")]
635-
pub fn from_mut(t: &mut T) -> &Cell<T> {
638+
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
639+
pub const fn from_mut(t: &mut T) -> &Cell<T> {
636640
// SAFETY: `&mut` ensures unique access.
637641
unsafe { &*(t as *mut T as *const Cell<T>) }
638642
}
@@ -686,7 +690,8 @@ impl<T> Cell<[T]> {
686690
/// assert_eq!(slice_cell.len(), 3);
687691
/// ```
688692
#[stable(feature = "as_cell", since = "1.37.0")]
689-
pub fn as_slice_of_cells(&self) -> &[Cell<T>] {
693+
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
694+
pub const fn as_slice_of_cells(&self) -> &[Cell<T>] {
690695
// SAFETY: `Cell<T>` has the same memory layout as `T`.
691696
unsafe { &*(self as *const Cell<[T]> as *const [Cell<T>]) }
692697
}
@@ -706,7 +711,8 @@ impl<T, const N: usize> Cell<[T; N]> {
706711
/// let array_cell: &[Cell<i32>; 3] = cell_array.as_array_of_cells();
707712
/// ```
708713
#[unstable(feature = "as_array_of_cells", issue = "88248")]
709-
pub fn as_array_of_cells(&self) -> &[Cell<T>; N] {
714+
#[rustc_const_unstable(feature = "as_array_of_cells", issue = "88248")]
715+
pub const fn as_array_of_cells(&self) -> &[Cell<T>; N] {
710716
// SAFETY: `Cell<T>` has the same memory layout as `T`.
711717
unsafe { &*(self as *const Cell<[T; N]> as *const [Cell<T>; N]) }
712718
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy