Skip to content

Commit f66ed40

Browse files
committed
Add impl const for Clone
1 parent cdac44e commit f66ed40

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed

library/core/src/clone.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ mod impls {
543543
($($t:ty)*) => {
544544
$(
545545
#[stable(feature = "rust1", since = "1.0.0")]
546-
impl Clone for $t {
546+
#[rustc_const_unstable(feature = "const_clone", issue = "142757")]
547+
impl const Clone for $t {
547548
#[inline(always)]
548549
fn clone(&self) -> Self {
549550
*self
@@ -561,7 +562,8 @@ mod impls {
561562
}
562563

563564
#[unstable(feature = "never_type", issue = "35121")]
564-
impl Clone for ! {
565+
#[rustc_const_unstable(feature = "const_clone", issue = "142757")]
566+
impl const Clone for ! {
565567
#[inline]
566568
fn clone(&self) -> Self {
567569
*self
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#![feature(
2+
const_trait_impl, const_default, const_clone, ptr_alignment_type,
3+
ascii_char, f16, f128, sync_unsafe_cell,
4+
)]
5+
#![allow(dead_code)]
6+
// core::default
7+
const UNIT: () = Default::default();
8+
const BOOL: bool = Default::default();
9+
const CHAR: char = Default::default();
10+
const ASCII_CHAR: std::ascii::Char = Default::default();
11+
const USIZE: usize = Default::default();
12+
const U8: u8 = Default::default();
13+
const U16: u16 = Default::default();
14+
const U32: u32 = Default::default();
15+
const U64: u64 = Default::default();
16+
const U128: u128 = Default::default();
17+
const I8: i8 = Default::default();
18+
const I16: i16 = Default::default();
19+
const I32: i32 = Default::default();
20+
const I64: i64 = Default::default();
21+
const I128: i128 = Default::default();
22+
const F16: f16 = Default::default();
23+
const F32: f32 = Default::default();
24+
const F64: f64 = Default::default();
25+
const F128: f128 = Default::default();
26+
// core::marker
27+
const PHANTOM: std::marker::PhantomData<()> = Default::default();
28+
// core::option
29+
const OPT: Option<i32> = Default::default();
30+
// core::iter::sources::empty
31+
const EMPTY: std::iter::Empty<()> = Default::default();
32+
// core::ptr::alignment
33+
const ALIGNMENT: std::ptr::Alignment = Default::default();
34+
// core::slice
35+
const SLICE: &[()] = Default::default();
36+
const MUT_SLICE: &mut [()] = Default::default();
37+
// core::str
38+
const STR: &str = Default::default();
39+
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();
45+
46+
// core::clone
47+
const UNIT_CLONE: () = UNIT.clone();
48+
//~^ ERROR: the trait bound `(): const Clone` is not satisfied
49+
const BOOL_CLONE: bool = BOOL.clone();
50+
const CHAR_CLONE: char = CHAR.clone();
51+
const ASCII_CHAR_CLONE: std::ascii::Char = ASCII_CHAR.clone();
52+
//~^ ERROR: the trait bound `Char: const Clone` is not satisfied
53+
const USIZE_CLONE: usize = USIZE.clone();
54+
const U8_CLONE: u8 = U8.clone();
55+
const U16_CLONE: u16 = U16.clone();
56+
const U32_CLONE: u32 = U32.clone();
57+
const U64_CLONE: u64 = U64.clone();
58+
const U128_CLONE: u128 = U128.clone();
59+
const I8_CLONE: i8 = I8.clone();
60+
const I16_CLONE: i16 = I16.clone();
61+
const I32_CLONE: i32 = I32.clone();
62+
const I64_CLONE: i64 = I64.clone();
63+
const I128_CLONE: i128 = I128.clone();
64+
const F16_CLONE: f16 = F16.clone();
65+
const F32_CLONE: f32 = F32.clone();
66+
const F64_CLONE: f64 = F64.clone();
67+
const F128_CLONE: f128 = F128.clone();
68+
69+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `(): const Clone` is not satisfied
2+
--> $DIR/const-clone.rs:47:29
3+
|
4+
LL | const UNIT_CLONE: () = UNIT.clone();
5+
| ^^^^^
6+
7+
error[E0277]: the trait bound `Char: const Clone` is not satisfied
8+
--> $DIR/const-clone.rs:51:55
9+
|
10+
LL | const ASCII_CHAR_CLONE: std::ascii::Char = ASCII_CHAR.clone();
11+
| ^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)