diff --git a/crossbeam-channel/src/flavors/array.rs b/crossbeam-channel/src/flavors/array.rs index 63b82eb85..fc8e40d2b 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 230edd8d2..638d6c2ba 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 c37de2dee..cc84564df 100644 --- a/crossbeam-deque/src/deque.rs +++ b/crossbeam-deque/src/deque.rs @@ -1987,8 +1987,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 950043881..76c326beb 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 1c7b99afe..bf23454a1 100644 --- a/crossbeam-queue/src/array_queue.rs +++ b/crossbeam-queue/src/array_queue.rs @@ -476,8 +476,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 fc29c9886..973a77f81 100644 --- a/crossbeam-queue/src/seg_queue.rs +++ b/crossbeam-queue/src/seg_queue.rs @@ -459,8 +459,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(); @@ -525,8 +524,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() }; } } }