diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2020-09-05 14:09:33 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2020-09-05 14:10:10 +0200 |
| commit | 578e7143936158a0130f17bedcc946cae62583f3 (patch) | |
| tree | 3decdba35a9db6bdbc7e0b47035edf40b7bccb69 /library/std/src/lazy.rs | |
| parent | c3364780d2cfddfe329f62a3ec138fd4f9a60e27 (diff) | |
| download | rust-578e7143936158a0130f17bedcc946cae62583f3.tar.gz rust-578e7143936158a0130f17bedcc946cae62583f3.zip | |
Fix dropck issue of SyncOnceCell.
Fixes #76367.
Diffstat (limited to 'library/std/src/lazy.rs')
| -rw-r--r-- | library/std/src/lazy.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs index 845e9d76a77..fc485f0cd47 100644 --- a/library/std/src/lazy.rs +++ b/library/std/src/lazy.rs @@ -6,6 +6,7 @@ mod tests; use crate::{ cell::{Cell, UnsafeCell}, fmt, + marker::PhantomData, mem::{self, MaybeUninit}, ops::{Deref, Drop}, panic::{RefUnwindSafe, UnwindSafe}, @@ -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`? @@ -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. |
