Skip to content

Commit bb9aeda

Browse files
Make Clone a const_trait
1 parent f9c15f4 commit bb9aeda

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

library/core/src/clone.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
3737
#![stable(feature = "rust1", since = "1.0.0")]
3838

39-
use crate::marker::PointeeSized;
39+
use crate::marker::{Destruct, PointeeSized};
4040

4141
mod uninit;
4242

@@ -157,6 +157,8 @@ mod uninit;
157157
#[lang = "clone"]
158158
#[rustc_diagnostic_item = "Clone"]
159159
#[rustc_trivial_field_reads]
160+
#[rustc_const_unstable(feature = "const_clone", issue = "12345")]
161+
#[const_trait]
160162
pub trait Clone: Sized {
161163
/// Returns a duplicate of the value.
162164
///
@@ -208,7 +210,9 @@ pub trait Clone: Sized {
208210
/// allocations.
209211
#[inline]
210212
#[stable(feature = "rust1", since = "1.0.0")]
211-
fn clone_from(&mut self, source: &Self) {
213+
fn clone_from(&mut self, source: &Self)
214+
where
215+
Self: ~const Destruct, {
212216
*self = source.clone()
213217
}
214218
}

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#![feature(cfg_select)]
104104
#![feature(cfg_target_has_reliable_f16_f128)]
105105
#![feature(const_carrying_mul_add)]
106+
#![feature(const_destruct)]
106107
#![feature(const_eval_select)]
107108
#![feature(core_intrinsics)]
108109
#![feature(coverage_attribute)]

0 commit comments

Comments
 (0)