From 91851432c874bacc8e5c4e2a5c4c846ce81289d6 Mon Sep 17 00:00:00 2001 From: Daniel Bloom <7810950-Daniel.Aaron.Bloom@users.noreply.gitlab.com> Date: Thu, 19 Jun 2025 16:21:49 -0700 Subject: [PATCH] Make `Clone` a `const_trait` --- library/core/src/clone.rs | 9 +++++++-- 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 57de507a73e82..a34d1b4a06497 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 88855831788db..72132d365cc0b 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)]