Skip to content

Commit

Permalink
Fix dropck issue of SyncOnceCell.
Browse files Browse the repository at this point in the history
Fixes #76367.
  • Loading branch information
m-ou-se committed Sep 5, 2020
1 parent c336478 commit 578e714
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion library/std/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod tests;
use crate::{
cell::{Cell, UnsafeCell},
fmt,
marker::PhantomData,
mem::{self, MaybeUninit},
ops::{Deref, Drop},
panic::{RefUnwindSafe, UnwindSafe},
Expand Down Expand Up @@ -46,6 +47,8 @@ pub struct SyncOnceCell<T> {
once: Once,
// Whether or not the value is initialized is tracked by `state_and_queue`.
value: UnsafeCell<MaybeUninit<T>>,
// Make sure dropck understands we're dropping T in our Drop impl.
_marker: PhantomData<T>,
}

// Why do we need `T: Send`?
Expand Down Expand Up @@ -119,7 +122,11 @@ impl<T> SyncOnceCell<T> {
/// Creates a new empty cell.
#[unstable(feature = "once_cell", issue = "74465")]
pub const fn new() -> SyncOnceCell<T> {
SyncOnceCell { once: Once::new(), value: UnsafeCell::new(MaybeUninit::uninit()) }
SyncOnceCell {
once: Once::new(),
value: UnsafeCell::new(MaybeUninit::uninit()),
_marker: PhantomData,
}
}

/// Gets the reference to the underlying value.
Expand Down

0 comments on commit 578e714

Please sign in to comment.