summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-02-15 11:41:33 +0100
committerRalf Jung <post@ralfj.de>2023-02-15 17:40:27 +0100
commit967ebb9c3d21d1692b0fa51112eee71c1b4668c4 (patch)
treec46d412e9434f2d306fdc2262fea6511586f0b90 /tests
parent60a0782390e2063d2d0a24c798bfd37cb2a42611 (diff)
downloadrust-967ebb9c3d21d1692b0fa51112eee71c1b4668c4.tar.gz
add test for may_dangle and ManuallyDrop
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/drop/dropck-eyepatch-manuallydrop.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/ui/drop/dropck-eyepatch-manuallydrop.rs b/tests/ui/drop/dropck-eyepatch-manuallydrop.rs
new file mode 100644
index 00000000000..ff100cd941f
--- /dev/null
+++ b/tests/ui/drop/dropck-eyepatch-manuallydrop.rs
@@ -0,0 +1,22 @@
+// check-pass
+//! This test checks that dropck knows that ManuallyDrop does not drop its field.
+#![feature(dropck_eyepatch)]
+
+use std::mem::ManuallyDrop;
+
+struct S<T>(ManuallyDrop<T>);
+
+unsafe impl<#[may_dangle] T> Drop for S<T> {
+ fn drop(&mut self) {}
+}
+
+struct NonTrivialDrop<'a>(&'a str);
+impl<'a> Drop for NonTrivialDrop<'a> {
+ fn drop(&mut self) {}
+}
+
+fn main() {
+ let s = String::from("string");
+ let _t = S(ManuallyDrop::new(NonTrivialDrop(&s)));
+ drop(s);
+}