Replace WriteCloneIntoRaw
with CloneToUninit
. · model-checking/verify-rust-std@5ac719e (original) (raw)
5 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -424,29 +424,3 @@ pub mod __alloc_error_handler { | ||
424 | 424 | } |
425 | 425 | } |
426 | 426 | } |
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 number | Diff line number | Diff line change |
---|---|---|
@@ -188,6 +188,8 @@ | ||
188 | 188 | use core::any::Any; |
189 | 189 | use core::async_iter::AsyncIterator; |
190 | 190 | use core::borrow; |
191 | +#[cfg(not(no_global_oom_handling))] | |
192 | +use core::clone::CloneToUninit; | |
191 | 193 | use core::cmp::Ordering; |
192 | 194 | use core::error::Error; |
193 | 195 | use core::fmt; |
@@ -207,7 +209,7 @@ use core::slice; | ||
207 | 209 | use core::task::{Context, Poll}; |
208 | 210 | |
209 | 211 | #[cfg(not(no_global_oom_handling))] |
210 | -use crate::alloc::{handle_alloc_error, WriteCloneIntoRaw}; | |
212 | +use crate::alloc::handle_alloc_error; | |
211 | 213 | use crate::alloc::{AllocError, Allocator, Global, Layout}; |
212 | 214 | #[cfg(not(no_global_oom_handling))] |
213 | 215 | use crate::borrow::Cow; |
@@ -1346,7 +1348,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> { | ||
1346 | 1348 | // Pre-allocate memory to allow writing the cloned value directly. |
1347 | 1349 | let mut boxed = Self::new_uninit_in(self.1.clone()); |
1348 | 1350 | unsafe { |
1349 | -(**self).write_clone_into_raw(boxed.as_mut_ptr()); | |
1351 | +(**self).clone_to_uninit(boxed.as_mut_ptr()); | |
1350 | 1352 | boxed.assume_init() |
1351 | 1353 | } |
1352 | 1354 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -103,6 +103,7 @@ | ||
103 | 103 | #![feature(assert_matches)] |
104 | 104 | #![feature(async_fn_traits)] |
105 | 105 | #![feature(async_iterator)] |
106 | +#![feature(clone_to_uninit)] | |
106 | 107 | #![feature(coerce_unsized)] |
107 | 108 | #![feature(const_align_of_val)] |
108 | 109 | #![feature(const_box)] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -249,6 +249,8 @@ use std::boxed::Box; | ||
249 | 249 | use core::any::Any; |
250 | 250 | use core::borrow; |
251 | 251 | use core::cell::Cell; |
252 | +#[cfg(not(no_global_oom_handling))] | |
253 | +use core::clone::CloneToUninit; | |
252 | 254 | use core::cmp::Ordering; |
253 | 255 | use core::fmt; |
254 | 256 | use core::hash::{Hash, Hasher}; |
@@ -268,8 +270,6 @@ use core::slice::from_raw_parts_mut; | ||
268 | 270 | |
269 | 271 | #[cfg(not(no_global_oom_handling))] |
270 | 272 | use crate::alloc::handle_alloc_error; |
271 | -#[cfg(not(no_global_oom_handling))] | |
272 | -use crate::alloc::WriteCloneIntoRaw; | |
273 | 273 | use crate::alloc::{AllocError, Allocator, Global, Layout}; |
274 | 274 | use crate::borrow::{Cow, ToOwned}; |
275 | 275 | #[cfg(not(no_global_oom_handling))] |
@@ -1810,7 +1810,7 @@ impl<T: Clone, A: Allocator + Clone> Rc<T, A> { | ||
1810 | 1810 | let mut rc = Self::new_uninit_in(this.alloc.clone()); |
1811 | 1811 | unsafe { |
1812 | 1812 | 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()); | |
1814 | 1814 | *this = rc.assume_init(); |
1815 | 1815 | } |
1816 | 1816 | } else if Rc::weak_count(this) != 0 { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -10,6 +10,8 @@ | ||
10 | 10 | |
11 | 11 | use core::any::Any; |
12 | 12 | use core::borrow; |
13 | +#[cfg(not(no_global_oom_handling))] | |
14 | +use core::clone::CloneToUninit; | |
13 | 15 | use core::cmp::Ordering; |
14 | 16 | use core::fmt; |
15 | 17 | use core::hash::{Hash, Hasher}; |
@@ -30,8 +32,6 @@ use core::sync::atomic::Ordering::{Acquire, Relaxed, Release}; | ||
30 | 32 | |
31 | 33 | #[cfg(not(no_global_oom_handling))] |
32 | 34 | use crate::alloc::handle_alloc_error; |
33 | -#[cfg(not(no_global_oom_handling))] | |
34 | -use crate::alloc::WriteCloneIntoRaw; | |
35 | 35 | use crate::alloc::{AllocError, Allocator, Global, Layout}; |
36 | 36 | use crate::borrow::{Cow, ToOwned}; |
37 | 37 | use crate::boxed::Box; |
@@ -2219,7 +2219,7 @@ impl<T: Clone, A: Allocator + Clone> Arc<T, A> { | ||
2219 | 2219 | let mut arc = Self::new_uninit_in(this.alloc.clone()); |
2220 | 2220 | unsafe { |
2221 | 2221 | 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()); | |
2223 | 2223 | *this = arc.assume_init(); |
2224 | 2224 | } |
2225 | 2225 | } else if this.inner().weak.load(Relaxed) != 1 { |