From 578e7143936158a0130f17bedcc946cae62583f3 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 5 Sep 2020 14:09:33 +0200 Subject: [PATCH] Fix dropck issue of SyncOnceCell. Fixes #76367. --- library/std/src/lazy.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs index 845e9d76a772..fc485f0cd47b 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 { once: Once, // Whether or not the value is initialized is tracked by `state_and_queue`. value: UnsafeCell>, + // Make sure dropck understands we're dropping T in our Drop impl. + _marker: PhantomData, } // Why do we need `T: Send`? @@ -119,7 +122,11 @@ impl SyncOnceCell { /// Creates a new empty cell. #[unstable(feature = "once_cell", issue = "74465")] pub const fn new() -> SyncOnceCell { - 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.