Skip to content

Commit f74d383

Browse files
committed
Add const Default for *Cell
1 parent cd6771d commit f74d383

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-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> {
@@ -1318,7 +1319,8 @@ impl<T: Clone> Clone for RefCell<T> {
13181319
}
13191320

13201321
#[stable(feature = "rust1", since = "1.0.0")]
1321-
impl<T: Default> Default for RefCell<T> {
1322+
#[rustc_const_unstable(feature = "const_default", issue = "none")]
1323+
impl<T: ~const Default> const Default for RefCell<T> {
13221324
/// Creates a `RefCell<T>`, with the `Default` value for T.
13231325
#[inline]
13241326
fn default() -> RefCell<T> {
@@ -2316,7 +2318,8 @@ impl<T: ?Sized> UnsafeCell<T> {
23162318
}
23172319

23182320
#[stable(feature = "unsafe_cell_default", since = "1.10.0")]
2319-
impl<T: Default> Default for UnsafeCell<T> {
2321+
#[rustc_const_unstable(feature = "const_default", issue = "none")]
2322+
impl<T: ~const Default> const Default for UnsafeCell<T> {
23202323
/// Creates an `UnsafeCell`, with the `Default` value for T.
23212324
fn default() -> UnsafeCell<T> {
23222325
UnsafeCell::new(Default::default())
@@ -2423,7 +2426,8 @@ impl<T: ?Sized> SyncUnsafeCell<T> {
24232426
}
24242427

24252428
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2426-
impl<T: Default> Default for SyncUnsafeCell<T> {
2429+
#[rustc_const_unstable(feature = "const_default", issue = "none")]
2430+
impl<T: ~const Default> const Default for SyncUnsafeCell<T> {
24272431
/// Creates an `SyncUnsafeCell`, with the `Default` value for T.
24282432
fn default() -> SyncUnsafeCell<T> {
24292433
SyncUnsafeCell::new(Default::default())

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ run-pass
2-
#![feature(const_trait_impl, ptr_alignment_type, ascii_char, f16, f128)]
2+
#![feature(const_trait_impl, ptr_alignment_type, ascii_char, f16, f128, sync_unsafe_cell)]
33
#![allow(dead_code)]
44
// core::default
55
const UNIT: () = Default::default();
@@ -32,8 +32,13 @@ const ALIGNMENT: std::ptr::Alignment = Default::default();
3232
// core::slice
3333
const SLICE: &[()] = Default::default();
3434
const MUT_SLICE: &mut [()] = Default::default();
35-
//core::str
35+
// core::str
3636
const STR: &str = Default::default();
3737
const MUT_STR: &mut str = Default::default();
38+
// core::cell
39+
const CELL: std::cell::Cell<()> = Default::default();
40+
const REF_CELL: std::cell::RefCell<()> = Default::default();
41+
const UNSAFE_CELL: std::cell::UnsafeCell<()> = Default::default();
42+
const SYNC_UNSAFE_CELL: std::cell::SyncUnsafeCell<()> = Default::default();
3843

3944
fn main() {}

0 commit comments

Comments
 (0)