diff options
| author | Daniel Bloom <7810950-Daniel.Aaron.Bloom@users.noreply.gitlab.com> | 2025-06-19 16:21:49 -0700 |
|---|---|---|
| committer | Daniel Bloom <7810950-Daniel.Aaron.Bloom@users.noreply.gitlab.com> | 2025-06-19 16:36:33 -0700 |
| commit | 91851432c874bacc8e5c4e2a5c4c846ce81289d6 (patch) | |
| tree | e6ef57f4dd6e8517ad3f478766ccffe5467cfdcf | |
| parent | f9c15f40fbd7b4ba1baea6fb89551274047e17b3 (diff) | |
Make `Clone` a `const_trait`
| -rw-r--r-- | library/core/src/clone.rs | 9 | ||||
| -rw-r--r-- | library/core/src/lib.rs | 1 |
2 files changed, 8 insertions, 2 deletions
diff --git a/library/core/src/clone.rs b/library/core/src/clone.rs index 57de507a73e..a34d1b4a064 100644 --- a/library/core/src/clone.rs +++ b/library/core/src/clone.rs @@ -36,7 +36,7 @@ #![stable(feature = "rust1", since = "1.0.0")] -use crate::marker::PointeeSized; +use crate::marker::{Destruct, PointeeSized}; mod uninit; @@ -157,6 +157,8 @@ mod uninit; #[lang = "clone"] #[rustc_diagnostic_item = "Clone"] #[rustc_trivial_field_reads] +#[rustc_const_unstable(feature = "const_clone", issue = "142757")] +#[const_trait] pub trait Clone: Sized { /// Returns a duplicate of the value. /// @@ -208,7 +210,10 @@ pub trait Clone: Sized { /// allocations. #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn clone_from(&mut self, source: &Self) { + fn clone_from(&mut self, source: &Self) + where + Self: ~const Destruct, + { *self = source.clone() } } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 88855831788..72132d365cc 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -103,6 +103,7 @@ #![feature(cfg_select)] #![feature(cfg_target_has_reliable_f16_f128)] #![feature(const_carrying_mul_add)] +#![feature(const_destruct)] #![feature(const_eval_select)] #![feature(core_intrinsics)] #![feature(coverage_attribute)] |
