Skip to content

Commit e56ea68

Browse files
committed
Add compile_fail test for SyncOnceCell's dropck issue.
1 parent 578e714 commit e56ea68

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

library/std/src/lazy.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,25 @@ pub struct SyncOnceCell<T> {
4747
once: Once,
4848
// Whether or not the value is initialized is tracked by `state_and_queue`.
4949
value: UnsafeCell<MaybeUninit<T>>,
50-
// Make sure dropck understands we're dropping T in our Drop impl.
50+
/// `PhantomData` to make sure dropck understands we're dropping T in our Drop impl.
51+
///
52+
/// ```compile_fail,E0597
53+
/// #![feature(once_cell)]
54+
///
55+
/// use std::lazy::SyncOnceCell;
56+
///
57+
/// struct A<'a>(&'a str);
58+
///
59+
/// impl<'a> Drop for A<'a> {
60+
/// fn drop(&mut self) {}
61+
/// }
62+
///
63+
/// let cell = SyncOnceCell::new();
64+
/// {
65+
/// let s = String::new();
66+
/// let _ = cell.set(A(&s));
67+
/// }
68+
/// ```
5169
_marker: PhantomData<T>,
5270
}
5371

0 commit comments

Comments
 (0)