diff --git a/tokio/src/sync/once_cell.rs b/tokio/src/sync/once_cell.rs index 858267b783d..a8ae0a61763 100644 --- a/tokio/src/sync/once_cell.rs +++ b/tokio/src/sync/once_cell.rs @@ -263,10 +263,10 @@ impl OnceCell { /// Moves the value out of the cell and drops the cell afterwards. /// /// Returns `None` if the cell is uninitialized. - pub fn into_inner(self) -> Option { + pub fn into_inner(mut self) -> Option { if self.initialized() { // Set to uninitialized for the destructor of `OnceCell` to work properly - self.value_set.store(false, Ordering::Release); + *self.value_set.get_mut() = false; Some(unsafe { self.value.with(|ptr| ptr::read(ptr).assume_init()) }) } else { None diff --git a/tokio/tests/sync_once_cell.rs b/tokio/tests/sync_once_cell.rs index de950446609..cd6b9813cde 100644 --- a/tokio/tests/sync_once_cell.rs +++ b/tokio/tests/sync_once_cell.rs @@ -1,6 +1,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "full")] +use std::mem; use std::ops::Drop; use std::sync::atomic::{AtomicU32, Ordering}; use std::time::Duration; @@ -181,7 +182,10 @@ fn drop_into_inner() { let once_cell = OnceCell::new(); let _ = once_cell.set(fooer); - let _v = once_cell.into_inner(); + let fooer = once_cell.into_inner(); let count = NUM_DROPS.load(Ordering::Acquire); assert!(count == 0); + mem::drop(fooer); + let count = NUM_DROPS.load(Ordering::Acquire); + assert(count == 1); }