about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <t.gross35@gmail.com>2025-06-20 23:25:57 -0400
committerGitHub <noreply@github.com>2025-06-20 23:25:57 -0400
commitc386ffb5ad8e45dbfd9a81c27aebb4dd8d1a2937 (patch)
tree740e54044448b2c69789335491c49b2039cf51fa
parent44d50f9acfd87cdfec66f519b9800fbaa9f5a5de (diff)
parent91851432c874bacc8e5c4e2a5c4c846ce81289d6 (diff)
Rollup merge of #142756 - Daniel-Aaron-Bloom:const-clone, r=oli-obk
Make `Clone` a `const_trait`

See [tracking issue](https://github.com/rust-lang/rust/issues/142757) for justification.
-rw-r--r--library/core/src/clone.rs9
-rw-r--r--library/core/src/lib.rs1
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 6231c3425c8..39d5399101d 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)]