summaryrefslogtreecommitdiffstats
path: root/tests/ui/dropck/dropck-union.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/dropck/dropck-union.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/dropck/dropck-union.rs')
-rw-r--r--tests/ui/dropck/dropck-union.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/ui/dropck/dropck-union.rs b/tests/ui/dropck/dropck-union.rs
new file mode 100644
index 000000000..5a9965db5
--- /dev/null
+++ b/tests/ui/dropck/dropck-union.rs
@@ -0,0 +1,38 @@
+use std::cell::Cell;
+use std::ops::Deref;
+use std::mem::ManuallyDrop;
+
+union Wrap<T> { x: ManuallyDrop<T> }
+
+impl<T> Drop for Wrap<T> {
+ fn drop(&mut self) {
+ unsafe { std::ptr::drop_in_place(&mut *self.x as *mut T); }
+ }
+}
+
+impl<T> Wrap<T> {
+ fn new(x: T) -> Self {
+ Wrap { x: ManuallyDrop::new(x) }
+ }
+}
+
+impl<T> Deref for Wrap<T> {
+ type Target = T;
+ #[inline]
+ fn deref(&self) -> &Self::Target {
+ unsafe {
+ &self.x
+ }
+ }
+}
+
+struct C<'a>(Cell<Option<&'a C<'a>>>);
+
+impl<'a> Drop for C<'a> {
+ fn drop(&mut self) {}
+}
+
+fn main() {
+ let v : Wrap<C> = Wrap::new(C(Cell::new(None)));
+ v.0.set(Some(&v)); //~ ERROR: `v` does not live long enough
+}