Replace `WriteCloneIntoRaw` with `CloneToUninit`. · rust-lang/rust@a9a4830

5 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -424,29 +424,3 @@ pub mod __alloc_error_handler {

424424

}

425425

}

426426

}

427-
428-

#[cfg(not(no_global_oom_handling))]

429-

/// Specialize clones into pre-allocated, uninitialized memory.

430-

/// Used by `Box::clone` and `Rc`/`Arc::make_mut`.

431-

pub(crate) trait WriteCloneIntoRaw: Sized {

432-

unsafe fn write_clone_into_raw(&self, target: *mut Self);

433-

}

434-
435-

#[cfg(not(no_global_oom_handling))]

436-

impl<T: Clone> WriteCloneIntoRaw for T {

437-

#[inline]

438-

default unsafe fn write_clone_into_raw(&self, target: *mut Self) {

439-

// Having allocated *first* may allow the optimizer to create

440-

// the cloned value in-place, skipping the local and move.

441-

unsafe { target.write(self.clone()) };

442-

}

443-

}

444-
445-

#[cfg(not(no_global_oom_handling))]

446-

impl<T: Copy> WriteCloneIntoRaw for T {

447-

#[inline]

448-

unsafe fn write_clone_into_raw(&self, target: *mut Self) {

449-

// We can always copy in-place, without ever involving a local value.

450-

unsafe { target.copy_from_nonoverlapping(self, 1) };

451-

}

452-

}

Original file line numberDiff line numberDiff line change

@@ -188,6 +188,8 @@

188188

use core::any::Any;

189189

use core::async_iter::AsyncIterator;

190190

use core::borrow;

191+

#[cfg(not(no_global_oom_handling))]

192+

use core::clone::CloneToUninit;

191193

use core::cmp::Ordering;

192194

use core::error::Error;

193195

use core::fmt;

@@ -207,7 +209,7 @@ use core::slice;

207209

use core::task::{Context, Poll};

208210
209211

#[cfg(not(no_global_oom_handling))]

210-

use crate::alloc::{handle_alloc_error, WriteCloneIntoRaw};

212+

use crate::alloc::handle_alloc_error;

211213

use crate::alloc::{AllocError, Allocator, Global, Layout};

212214

#[cfg(not(no_global_oom_handling))]

213215

use crate::borrow::Cow;

@@ -1346,7 +1348,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {

13461348

// Pre-allocate memory to allow writing the cloned value directly.

13471349

let mut boxed = Self::new_uninit_in(self.1.clone());

13481350

unsafe {

1349-

(**self).write_clone_into_raw(boxed.as_mut_ptr());

1351+

(**self).clone_to_uninit(boxed.as_mut_ptr());

13501352

boxed.assume_init()

13511353

}

13521354

}

Original file line numberDiff line numberDiff line change

@@ -103,6 +103,7 @@

103103

#![feature(assert_matches)]

104104

#![feature(async_fn_traits)]

105105

#![feature(async_iterator)]

106+

#![feature(clone_to_uninit)]

106107

#![feature(coerce_unsized)]

107108

#![feature(const_align_of_val)]

108109

#![feature(const_box)]

Original file line numberDiff line numberDiff line change

@@ -249,6 +249,8 @@ use std::boxed::Box;

249249

use core::any::Any;

250250

use core::borrow;

251251

use core::cell::Cell;

252+

#[cfg(not(no_global_oom_handling))]

253+

use core::clone::CloneToUninit;

252254

use core::cmp::Ordering;

253255

use core::fmt;

254256

use core::hash::{Hash, Hasher};

@@ -268,8 +270,6 @@ use core::slice::from_raw_parts_mut;

268270
269271

#[cfg(not(no_global_oom_handling))]

270272

use crate::alloc::handle_alloc_error;

271-

#[cfg(not(no_global_oom_handling))]

272-

use crate::alloc::WriteCloneIntoRaw;

273273

use crate::alloc::{AllocError, Allocator, Global, Layout};

274274

use crate::borrow::{Cow, ToOwned};

275275

#[cfg(not(no_global_oom_handling))]

@@ -1810,7 +1810,7 @@ impl<T: Clone, A: Allocator + Clone> Rc<T, A> {

18101810

let mut rc = Self::new_uninit_in(this.alloc.clone());

18111811

unsafe {

18121812

let data = Rc::get_mut_unchecked(&mut rc);

1813-

(**this).write_clone_into_raw(data.as_mut_ptr());

1813+

(**this).clone_to_uninit(data.as_mut_ptr());

18141814

*this = rc.assume_init();

18151815

}

18161816

} else if Rc::weak_count(this) != 0 {

Original file line numberDiff line numberDiff line change

@@ -10,6 +10,8 @@

1010
1111

use core::any::Any;

1212

use core::borrow;

13+

#[cfg(not(no_global_oom_handling))]

14+

use core::clone::CloneToUninit;

1315

use core::cmp::Ordering;

1416

use core::fmt;

1517

use core::hash::{Hash, Hasher};

@@ -30,8 +32,6 @@ use core::sync::atomic::Ordering::{Acquire, Relaxed, Release};

3032
3133

#[cfg(not(no_global_oom_handling))]

3234

use crate::alloc::handle_alloc_error;

33-

#[cfg(not(no_global_oom_handling))]

34-

use crate::alloc::WriteCloneIntoRaw;

3535

use crate::alloc::{AllocError, Allocator, Global, Layout};

3636

use crate::borrow::{Cow, ToOwned};

3737

use crate::boxed::Box;

@@ -2219,7 +2219,7 @@ impl<T: Clone, A: Allocator + Clone> Arc<T, A> {

22192219

let mut arc = Self::new_uninit_in(this.alloc.clone());

22202220

unsafe {

22212221

let data = Arc::get_mut_unchecked(&mut arc);

2222-

(**this).write_clone_into_raw(data.as_mut_ptr());

2222+

(**this).clone_to_uninit(data.as_mut_ptr());

22232223

*this = arc.assume_init();

22242224

}

22252225

} else if this.inner().weak.load(Relaxed) != 1 {