Skip to content

Commit 578e714

Browse files
committed
Fix dropck issue of SyncOnceCell.
Fixes #76367.
1 parent c336478 commit 578e714

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

library/std/src/lazy.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod tests;
66
use crate::{
77
cell::{Cell, UnsafeCell},
88
fmt,
9+
marker::PhantomData,
910
mem::{self, MaybeUninit},
1011
ops::{Deref, Drop},
1112
panic::{RefUnwindSafe, UnwindSafe},
@@ -46,6 +47,8 @@ pub struct SyncOnceCell<T> {
4647
once: Once,
4748
// Whether or not the value is initialized is tracked by `state_and_queue`.
4849
value: UnsafeCell<MaybeUninit<T>>,
50+
// Make sure dropck understands we're dropping T in our Drop impl.
51+
_marker: PhantomData<T>,
4952
}
5053

5154
// Why do we need `T: Send`?
@@ -119,7 +122,11 @@ impl<T> SyncOnceCell<T> {
119122
/// Creates a new empty cell.
120123
#[unstable(feature = "once_cell", issue = "74465")]
121124
pub const fn new() -> SyncOnceCell<T> {
122-
SyncOnceCell { once: Once::new(), value: UnsafeCell::new(MaybeUninit::uninit()) }
125+
SyncOnceCell {
126+
once: Once::new(),
127+
value: UnsafeCell::new(MaybeUninit::uninit()),
128+
_marker: PhantomData,
129+
}
123130
}
124131

125132
/// Gets the reference to the underlying value.

0 commit comments

Comments
 (0)