Skip to content

Commit db0a0ab

Browse files
committed
Add const Default for *Cell
1 parent a84f90a commit db0a0ab

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

library/core/src/cell.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ impl<T: Copy> Clone for Cell<T> {
332332
}
333333

334334
#[stable(feature = "rust1", since = "1.0.0")]
335-
impl<T: Default> Default for Cell<T> {
335+
#[rustc_const_unstable(feature = "const_default", issue = "none")]
336+
impl<T: ~const Default> const Default for Cell<T> {
336337
/// Creates a `Cell<T>`, with the `Default` value for T.
337338
#[inline]
338339
fn default() -> Cell<T> {
@@ -1307,7 +1308,8 @@ impl<T: Clone> Clone for RefCell<T> {
13071308
}
13081309

13091310
#[stable(feature = "rust1", since = "1.0.0")]
1310-
impl<T: Default> Default for RefCell<T> {
1311+
#[rustc_const_unstable(feature = "const_default", issue = "none")]
1312+
impl<T: ~const Default> const Default for RefCell<T> {
13111313
/// Creates a `RefCell<T>`, with the `Default` value for T.
13121314
#[inline]
13131315
fn default() -> RefCell<T> {
@@ -2305,7 +2307,8 @@ impl<T: ?Sized> UnsafeCell<T> {
23052307
}
23062308

23072309
#[stable(feature = "unsafe_cell_default", since = "1.10.0")]
2308-
impl<T: Default> Default for UnsafeCell<T> {
2310+
#[rustc_const_unstable(feature = "const_default", issue = "none")]
2311+
impl<T: ~const Default> const Default for UnsafeCell<T> {
23092312
/// Creates an `UnsafeCell`, with the `Default` value for T.
23102313
fn default() -> UnsafeCell<T> {
23112314
UnsafeCell::new(Default::default())
@@ -2412,7 +2415,8 @@ impl<T: ?Sized> SyncUnsafeCell<T> {
24122415
}
24132416

24142417
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2415-
impl<T: Default> Default for SyncUnsafeCell<T> {
2418+
#[rustc_const_unstable(feature = "const_default", issue = "none")]
2419+
impl<T: ~const Default> const Default for SyncUnsafeCell<T> {
24162420
/// Creates an `SyncUnsafeCell`, with the `Default` value for T.
24172421
fn default() -> SyncUnsafeCell<T> {
24182422
SyncUnsafeCell::new(Default::default())

tests/ui/traits/const-traits/const-traits-core.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//@ run-pass
2-
#![feature(const_trait_impl, const_default, ptr_alignment_type, ascii_char, f16, f128)]
2+
#![feature(
3+
const_trait_impl, const_default, ptr_alignment_type, ascii_char, f16, f128, sync_unsafe_cell,
4+
)]
35
#![allow(dead_code)]
46
// core::default
57
const UNIT: () = Default::default();
@@ -32,8 +34,13 @@ const ALIGNMENT: std::ptr::Alignment = Default::default();
3234
// core::slice
3335
const SLICE: &[()] = Default::default();
3436
const MUT_SLICE: &mut [()] = Default::default();
35-
//core::str
37+
// core::str
3638
const STR: &str = Default::default();
3739
const MUT_STR: &mut str = Default::default();
40+
// core::cell
41+
const CELL: std::cell::Cell<()> = Default::default();
42+
const REF_CELL: std::cell::RefCell<()> = Default::default();
43+
const UNSAFE_CELL: std::cell::UnsafeCell<()> = Default::default();
44+
const SYNC_UNSAFE_CELL: std::cell::SyncUnsafeCell<()> = Default::default();
3845

3946
fn main() {}

0 commit comments

Comments
 (0)