about summary refs log tree commit diff
path: root/tests/ui/box/thin_drop.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/box/thin_drop.rs')
-rw-r--r--tests/ui/box/thin_drop.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/ui/box/thin_drop.rs b/tests/ui/box/thin_drop.rs
new file mode 100644
index 00000000000..965613c114e
--- /dev/null
+++ b/tests/ui/box/thin_drop.rs
@@ -0,0 +1,37 @@
+#![feature(thin_box)]
+// run-pass
+use std::boxed::ThinBox;
+use std::error::Error;
+use std::ops::Deref;
+use std::fmt;
+
+fn main() {
+    let expected = "Foo error!";
+    let mut dropped = false;
+    {
+        let foo = Foo(expected, &mut dropped);
+        let a: ThinBox<dyn Error> = ThinBox::new_unsize(foo);
+        let a = a.deref();
+        let msg = a.to_string();
+        assert_eq!(expected, msg);
+    }
+    assert!(dropped);
+}
+
+#[derive(Debug)]
+#[repr(align(1024))]
+struct Foo<'a>(&'static str, &'a mut bool);
+
+impl Drop for Foo<'_> {
+    fn drop(&mut self) {
+        *self.1 = true;
+    }
+}
+
+impl fmt::Display for Foo<'_> {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "{}", self.0)
+    }
+}
+
+impl Error for Foo<'_> {}