diff --git a/src/once_cell.rs b/src/once_cell.rs index 079b9b4..463dc62 100644 --- a/src/once_cell.rs +++ b/src/once_cell.rs @@ -749,7 +749,11 @@ impl fmt::Debug for OnceCell { impl Drop for OnceCell { 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::().drop_in_place() } + } } }