diff --git a/crossbeam-channel/src/flavors/array.rs b/crossbeam-channel/src/flavors/array.rs index 16ec7ac51..69b00b561 100644 --- a/crossbeam-channel/src/flavors/array.rs +++ b/crossbeam-channel/src/flavors/array.rs @@ -549,8 +549,7 @@ impl Drop for Channel { unsafe { debug_assert!(index < self.buffer.len()); let slot = self.buffer.get_unchecked_mut(index); - let msg = &mut *slot.msg.get(); - msg.as_mut_ptr().drop_in_place(); + (*slot.msg.get()).assume_init_drop(); } } } diff --git a/crossbeam-channel/src/flavors/list.rs b/crossbeam-channel/src/flavors/list.rs index 78a1ea365..15976967d 100644 --- a/crossbeam-channel/src/flavors/list.rs +++ b/crossbeam-channel/src/flavors/list.rs @@ -604,8 +604,7 @@ impl Channel { // Drop the message in the slot. let slot = (*block).slots.get_unchecked(offset); slot.wait_write(); - let p = &mut *slot.msg.get(); - p.as_mut_ptr().drop_in_place(); + (*slot.msg.get()).assume_init_drop(); } else { (*block).wait_next(); // Deallocate the block and move to the next one. @@ -663,8 +662,7 @@ impl Drop for Channel { if offset < BLOCK_CAP { // Drop the message in the slot. let slot = (*block).slots.get_unchecked(offset); - let p = &mut *slot.msg.get(); - p.as_mut_ptr().drop_in_place(); + (*slot.msg.get()).assume_init_drop(); } else { // Deallocate the block and move to the next one. let next = *(*block).next.get_mut(); diff --git a/crossbeam-deque/src/deque.rs b/crossbeam-deque/src/deque.rs index e733abae4..d4e7542fe 100644 --- a/crossbeam-deque/src/deque.rs +++ b/crossbeam-deque/src/deque.rs @@ -1986,8 +1986,7 @@ impl Drop for Injector { if offset < BLOCK_CAP { // Drop the task in the slot. let slot = (*block).slots.get_unchecked(offset); - let p = &mut *slot.task.get(); - p.as_mut_ptr().drop_in_place(); + (*slot.task.get()).assume_init_drop(); } else { // Deallocate the block and move to the next one. let next = *(*block).next.get_mut(); diff --git a/crossbeam-epoch/src/sync/queue.rs b/crossbeam-epoch/src/sync/queue.rs index cb0215edc..ffcca99f9 100644 --- a/crossbeam-epoch/src/sync/queue.rs +++ b/crossbeam-epoch/src/sync/queue.rs @@ -132,8 +132,7 @@ impl Queue { .compare_exchange(tail, next, Release, Relaxed, guard); } guard.defer_destroy(head); - // TODO: Replace with MaybeUninit::read when api is stable - Some(n.data.as_ptr().read()) + Some(n.data.assume_init_read()) }) .map_err(|_| ()) }, @@ -165,7 +164,7 @@ impl Queue { .compare_exchange(tail, next, Release, Relaxed, guard); } guard.defer_destroy(head); - Some(n.data.as_ptr().read()) + Some(n.data.assume_init_read()) }) .map_err(|_| ()) }, diff --git a/crossbeam-queue/src/array_queue.rs b/crossbeam-queue/src/array_queue.rs index a76d4f3e9..b3d78582b 100644 --- a/crossbeam-queue/src/array_queue.rs +++ b/crossbeam-queue/src/array_queue.rs @@ -472,8 +472,7 @@ impl Drop for ArrayQueue { unsafe { debug_assert!(index < self.buffer.len()); let slot = self.buffer.get_unchecked_mut(index); - let value = &mut *slot.value.get(); - value.as_mut_ptr().drop_in_place(); + (*slot.value.get()).assume_init_drop(); } } } diff --git a/crossbeam-queue/src/seg_queue.rs b/crossbeam-queue/src/seg_queue.rs index 9d660829c..6ae5d0ab6 100644 --- a/crossbeam-queue/src/seg_queue.rs +++ b/crossbeam-queue/src/seg_queue.rs @@ -455,8 +455,7 @@ impl Drop for SegQueue { if offset < BLOCK_CAP { // Drop the value in the slot. let slot = (*block).slots.get_unchecked(offset); - let p = &mut *slot.value.get(); - p.as_mut_ptr().drop_in_place(); + (*slot.value.get()).assume_init_drop(); } else { // Deallocate the block and move to the next one. let next = *(*block).next.get_mut(); @@ -521,8 +520,7 @@ impl Iterator for IntoIter { // and this is a non-empty queue. let item = unsafe { let slot = (*block).slots.get_unchecked(offset); - let p = &mut *slot.value.get(); - p.as_mut_ptr().read() + slot.value.get().read().assume_init() }; if offset + 1 == BLOCK_CAP { // Deallocate the block and move to the next one. diff --git a/crossbeam-utils/src/sync/once_lock.rs b/crossbeam-utils/src/sync/once_lock.rs index 761851b01..e057aca7d 100644 --- a/crossbeam-utils/src/sync/once_lock.rs +++ b/crossbeam-utils/src/sync/once_lock.rs @@ -61,13 +61,11 @@ impl OnceLock { where F: FnOnce() -> T, { - let slot = self.value.get().cast::(); + let slot = self.value.get(); self.once.call_once(|| { let value = f(); - unsafe { - slot.write(value); - } + unsafe { slot.write(MaybeUninit::new(value)) } }); } @@ -84,7 +82,7 @@ impl Drop for OnceLock { fn drop(&mut self) { if self.once.is_completed() { // SAFETY: The inner value has been initialized - unsafe { self.value.get().cast::().drop_in_place() }; + unsafe { (*self.value.get()).assume_init_drop() }; } } }