@@ -494,8 +494,9 @@ impl<T> Cell<T> {
494
494
/// ```
495
495
#[ inline]
496
496
#[ stable( feature = "move_cell" , since = "1.17.0" ) ]
497
+ #[ rustc_const_unstable( feature = "const_cell" , issue = "131283" ) ]
497
498
#[ rustc_confusables( "swap" ) ]
498
- pub fn replace ( & self , val : T ) -> T {
499
+ pub const fn replace ( & self , val : T ) -> T {
499
500
// SAFETY: This can cause data races if called from a separate thread,
500
501
// but `Cell` is `!Sync` so this won't happen.
501
502
mem:: replace ( unsafe { & mut * self . value . get ( ) } , val)
@@ -535,7 +536,8 @@ impl<T: Copy> Cell<T> {
535
536
/// ```
536
537
#[ inline]
537
538
#[ 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 {
539
541
// SAFETY: This can cause data races if called from a separate thread,
540
542
// but `Cell` is `!Sync` so this won't happen.
541
543
unsafe { * self . value . get ( ) }
@@ -613,7 +615,8 @@ impl<T: ?Sized> Cell<T> {
613
615
/// ```
614
616
#[ inline]
615
617
#[ 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 {
617
620
self . value . get_mut ( )
618
621
}
619
622
@@ -632,7 +635,8 @@ impl<T: ?Sized> Cell<T> {
632
635
/// ```
633
636
#[ inline]
634
637
#[ 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 > {
636
640
// SAFETY: `&mut` ensures unique access.
637
641
unsafe { & * ( t as * mut T as * const Cell < T > ) }
638
642
}
@@ -686,7 +690,8 @@ impl<T> Cell<[T]> {
686
690
/// assert_eq!(slice_cell.len(), 3);
687
691
/// ```
688
692
#[ 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 > ] {
690
695
// SAFETY: `Cell<T>` has the same memory layout as `T`.
691
696
unsafe { & * ( self as * const Cell < [ T ] > as * const [ Cell < T > ] ) }
692
697
}
@@ -706,7 +711,8 @@ impl<T, const N: usize> Cell<[T; N]> {
706
711
/// let array_cell: &[Cell<i32>; 3] = cell_array.as_array_of_cells();
707
712
/// ```
708
713
#[ 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 ] {
710
716
// SAFETY: `Cell<T>` has the same memory layout as `T`.
711
717
unsafe { & * ( self as * const Cell < [ T ; N ] > as * const [ Cell < T > ; N ] ) }
712
718
}
0 commit comments