From e56ea68db50d23f4a7efa712c53ba02e506fd61a Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 5 Sep 2020 15:55:20 +0200 Subject: [PATCH] Add compile_fail test for SyncOnceCell's dropck issue. --- library/std/src/lazy.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs index fc485f0cd47b..d171231b0f1e 100644 --- a/library/std/src/lazy.rs +++ b/library/std/src/lazy.rs @@ -47,7 +47,25 @@ 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. + /// `PhantomData` to make sure dropck understands we're dropping T in our Drop impl. + /// + /// ```compile_fail,E0597 + /// #![feature(once_cell)] + /// + /// use std::lazy::SyncOnceCell; + /// + /// struct A<'a>(&'a str); + /// + /// impl<'a> Drop for A<'a> { + /// fn drop(&mut self) {} + /// } + /// + /// let cell = SyncOnceCell::new(); + /// { + /// let s = String::new(); + /// let _ = cell.set(A(&s)); + /// } + /// ``` _marker: PhantomData, }