|
252 | 252 |
|
253 | 253 | use crate::cmp::Ordering; |
254 | 254 | use crate::fmt::{self, Debug, Display}; |
255 | | -use crate::marker::{PhantomData, Unsize}; |
| 255 | +use crate::marker::{Destruct, PhantomData, Unsize}; |
256 | 256 | use crate::mem::{self, ManuallyDrop}; |
257 | 257 | use crate::ops::{self, CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn}; |
258 | 258 | use crate::panic::const_panic; |
@@ -429,7 +429,11 @@ impl<T> Cell<T> { |
429 | 429 | /// ``` |
430 | 430 | #[inline] |
431 | 431 | #[stable(feature = "rust1", since = "1.0.0")] |
432 | | - pub fn set(&self, val: T) { |
| 432 | + #[rustc_const_unstable(feature = "const_cell_traits", issue = "147787")] |
| 433 | + pub const fn set(&self, val: T) |
| 434 | + where |
| 435 | + T: [const] Destruct, |
| 436 | + { |
433 | 437 | self.replace(val); |
434 | 438 | } |
435 | 439 |
|
@@ -561,7 +565,12 @@ impl<T: Copy> Cell<T> { |
561 | 565 | /// ``` |
562 | 566 | #[inline] |
563 | 567 | #[stable(feature = "cell_update", since = "1.88.0")] |
564 | | - pub fn update(&self, f: impl FnOnce(T) -> T) { |
| 568 | + #[rustc_const_unstable(feature = "const_cell_traits", issue = "147787")] |
| 569 | + pub const fn update(&self, f: impl [const] FnOnce(T) -> T) |
| 570 | + where |
| 571 | + // FIXME(const-hack): `Copy` should imply `const Destruct` |
| 572 | + T: [const] Destruct, |
| 573 | + { |
565 | 574 | let old = self.get(); |
566 | 575 | self.set(f(old)); |
567 | 576 | } |
@@ -654,7 +663,11 @@ impl<T: Default> Cell<T> { |
654 | 663 | /// assert_eq!(c.into_inner(), 0); |
655 | 664 | /// ``` |
656 | 665 | #[stable(feature = "move_cell", since = "1.17.0")] |
657 | | - pub fn take(&self) -> T { |
| 666 | + #[rustc_const_unstable(feature = "const_cell_traits", issue = "147787")] |
| 667 | + pub const fn take(&self) -> T |
| 668 | + where |
| 669 | + T: [const] Default, |
| 670 | + { |
658 | 671 | self.replace(Default::default()) |
659 | 672 | } |
660 | 673 | } |
|
0 commit comments