Skip to content

Commit c3d98de

Browse files
committed
Replace WriteCloneIntoRaw with CloneToUninit.
1 parent 7f16cf3 commit c3d98de

File tree

5 files changed

+8
-27
lines changed

5 files changed

+8
-27
lines changed

library/alloc/src/alloc.rs

-21
Original file line numberDiff line numberDiff line change
@@ -415,24 +415,3 @@ pub mod __alloc_error_handler {
415415
}
416416
}
417417
}
418-
419-
/// Specialize clones into pre-allocated, uninitialized memory.
420-
/// Used by `Box::clone` and `Rc`/`Arc::make_mut`.
421-
pub(crate) trait WriteCloneIntoRaw: Sized {
422-
unsafe fn write_clone_into_raw(&self, target: *mut Self);
423-
}
424-
425-
impl<T: Clone> WriteCloneIntoRaw for T {
426-
#[inline]
427-
default unsafe fn write_clone_into_raw(&self, target: *mut Self) {
428-
unsafe { target.write(self.clone()) };
429-
}
430-
}
431-
432-
impl<T: Copy> WriteCloneIntoRaw for T {
433-
#[inline]
434-
unsafe fn write_clone_into_raw(&self, target: *mut Self) {
435-
// We can always copy in-place, without ever involving a local value.
436-
unsafe { target.copy_from_nonoverlapping(self, 1) };
437-
}
438-
}

library/alloc/src/boxed.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
use core::any::Any;
150150
use core::async_iter::AsyncIterator;
151151
use core::borrow;
152+
use core::clone::CloneToUninit;
152153
use core::cmp::Ordering;
153154
use core::error::Error;
154155
use core::fmt;
@@ -166,7 +167,7 @@ use core::ptr::{self, NonNull, Unique};
166167
use core::task::{Context, Poll};
167168

168169
#[cfg(not(no_global_oom_handling))]
169-
use crate::alloc::{handle_alloc_error, WriteCloneIntoRaw};
170+
use crate::alloc::handle_alloc_error;
170171
use crate::alloc::{AllocError, Allocator, Global, Layout};
171172
#[cfg(not(no_global_oom_handling))]
172173
use crate::borrow::Cow;
@@ -1294,7 +1295,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
12941295
// Pre-allocate memory to allow writing the cloned value directly.
12951296
let mut boxed = Self::new_uninit_in(self.1.clone());
12961297
unsafe {
1297-
(**self).write_clone_into_raw(boxed.as_mut_ptr());
1298+
(**self).clone_to_uninit(boxed.as_mut_ptr());
12981299
boxed.assume_init()
12991300
}
13001301
}

library/alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
#![feature(ascii_char)]
107107
#![feature(assert_matches)]
108108
#![feature(async_iterator)]
109+
#![feature(clone_to_uninit)]
109110
#![feature(coerce_unsized)]
110111
#![feature(const_align_of_val)]
111112
#![feature(const_box)]

library/alloc/src/rc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ use std::boxed::Box;
249249
use core::any::Any;
250250
use core::borrow;
251251
use core::cell::Cell;
252+
use core::clone::CloneToUninit;
252253
use core::cmp::Ordering;
253254
use core::fmt;
254255
use core::hash::{Hash, Hasher};
@@ -270,7 +271,6 @@ use core::slice::from_raw_parts_mut;
270271
#[cfg(not(no_global_oom_handling))]
271272
use crate::alloc::handle_alloc_error;
272273
#[cfg(not(no_global_oom_handling))]
273-
use crate::alloc::WriteCloneIntoRaw;
274274
use crate::alloc::{AllocError, Allocator, Global, Layout};
275275
use crate::borrow::{Cow, ToOwned};
276276
#[cfg(not(no_global_oom_handling))]
@@ -1712,7 +1712,7 @@ impl<T: Clone, A: Allocator + Clone> Rc<T, A> {
17121712
let mut rc = Self::new_uninit_in(this.alloc.clone());
17131713
unsafe {
17141714
let data = Rc::get_mut_unchecked(&mut rc);
1715-
(**this).write_clone_into_raw(data.as_mut_ptr());
1715+
(**this).clone_to_uninit(data.as_mut_ptr());
17161716
*this = rc.assume_init();
17171717
}
17181718
} else if Rc::weak_count(this) != 0 {

library/alloc/src/sync.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
use core::any::Any;
1212
use core::borrow;
13+
use core::clone::CloneToUninit;
1314
use core::cmp::Ordering;
1415
use core::fmt;
1516
use core::hash::{Hash, Hasher};
@@ -33,7 +34,6 @@ use core::sync::atomic::Ordering::{Acquire, Relaxed, Release};
3334
#[cfg(not(no_global_oom_handling))]
3435
use crate::alloc::handle_alloc_error;
3536
#[cfg(not(no_global_oom_handling))]
36-
use crate::alloc::WriteCloneIntoRaw;
3737
use crate::alloc::{AllocError, Allocator, Global, Layout};
3838
use crate::borrow::{Cow, ToOwned};
3939
use crate::boxed::Box;
@@ -2124,7 +2124,7 @@ impl<T: Clone, A: Allocator + Clone> Arc<T, A> {
21242124
let mut arc = Self::new_uninit_in(this.alloc.clone());
21252125
unsafe {
21262126
let data = Arc::get_mut_unchecked(&mut arc);
2127-
(**this).write_clone_into_raw(data.as_mut_ptr());
2127+
(**this).clone_to_uninit(data.as_mut_ptr());
21282128
*this = arc.assume_init();
21292129
}
21302130
} else if this.inner().weak.load(Relaxed) != 1 {

0 commit comments

Comments
 (0)