Skip to content
Permalink
Browse files

Use ManuallyDrop instead of mem::forget

  • Loading branch information...
SimonSapin committed Jul 16, 2019
1 parent dab967a commit 1141136b90663cf9d5ee6325b2f9e47f02e70746
Showing with 4 additions and 12 deletions.
  1. +2 −6 src/liballoc/rc.rs
  2. +2 −6 src/liballoc/sync.rs
@@ -495,10 +495,8 @@ impl<T> Rc<mem::MaybeUninit<T>> {
#[unstable(feature = "new_uninit", issue = "0")]
#[inline]
pub unsafe fn assume_init(self) -> Rc<T> {
let ptr = self.ptr.cast();
mem::forget(self);
Rc {
ptr,
ptr: mem::ManuallyDrop::new(self).ptr.cast(),
phantom: PhantomData,
}
}
@@ -541,10 +539,8 @@ impl<T> Rc<[mem::MaybeUninit<T>]> {
#[unstable(feature = "new_uninit", issue = "0")]
#[inline]
pub unsafe fn assume_init(self) -> Rc<[T]> {
let ptr = NonNull::new_unchecked(self.ptr.as_ptr() as _);
mem::forget(self);
Rc {
ptr,
ptr: NonNull::new_unchecked(mem::ManuallyDrop::new(self).ptr.as_ptr() as _),
phantom: PhantomData,
}
}
@@ -479,10 +479,8 @@ impl<T> Arc<mem::MaybeUninit<T>> {
#[unstable(feature = "new_uninit", issue = "0")]
#[inline]
pub unsafe fn assume_init(self) -> Arc<T> {
let ptr = self.ptr.cast();
mem::forget(self);
Arc {
ptr,
ptr: mem::ManuallyDrop::new(self).ptr.cast(),
phantom: PhantomData,
}
}
@@ -525,10 +523,8 @@ impl<T> Arc<[mem::MaybeUninit<T>]> {
#[unstable(feature = "new_uninit", issue = "0")]
#[inline]
pub unsafe fn assume_init(self) -> Arc<[T]> {
let ptr = NonNull::new_unchecked(self.ptr.as_ptr() as _);
mem::forget(self);
Arc {
ptr,
ptr: NonNull::new_unchecked(mem::ManuallyDrop::new(self).ptr.as_ptr() as _),
phantom: PhantomData,
}
}

0 comments on commit 1141136

Please sign in to comment.
You can’t perform that action at this time.