Skip to content

Commit

Permalink
Do not copy data before dropping (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 25, 2022
1 parent 5f80166 commit 465e0e2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/once_cell.rs
Expand Up @@ -749,7 +749,11 @@ impl<T: fmt::Debug> fmt::Debug for OnceCell<T> {

impl<T> Drop for OnceCell<T> {
fn drop(&mut self) {
drop(self.take());
if State::from(*self.state.get_mut()) == State::Initialized {
// SAFETY: We know that the value is initialized, so it is safe to
// drop it.
unsafe { self.value.get().cast::<T>().drop_in_place() }
}
}
}

Expand Down

0 comments on commit 465e0e2

Please sign in to comment.