Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
b-naber committed Mar 26, 2021
1 parent 7b1be1a commit 33fce8e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tokio/src/sync/once_cell.rs
Expand Up @@ -263,10 +263,10 @@ impl<T> OnceCell<T> {
/// 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<T> {
pub fn into_inner(mut self) -> Option<T> {
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
Expand Down
6 changes: 5 additions & 1 deletion 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;
Expand Down Expand Up @@ -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);
}

0 comments on commit 33fce8e

Please sign in to comment.