about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-09-05 15:55:20 +0200
committerMara Bos <m-ou.se@m-ou.se>2020-09-05 15:55:20 +0200
commite56ea68db50d23f4a7efa712c53ba02e506fd61a (patch)
tree3ee8c1a62be92b10c4c910393585a1cacf68d060 /library/std/src
parent578e7143936158a0130f17bedcc946cae62583f3 (diff)
downloadrust-e56ea68db50d23f4a7efa712c53ba02e506fd61a.tar.gz
rust-e56ea68db50d23f4a7efa712c53ba02e506fd61a.zip
Add compile_fail test for SyncOnceCell's dropck issue.
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/lazy.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs
index fc485f0cd47..d171231b0f1 100644
--- a/library/std/src/lazy.rs
+++ b/library/std/src/lazy.rs
@@ -47,7 +47,25 @@ 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.
+    /// `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<T>,
 }