about summary refs log tree commit diff
path: root/tests/ui/union/union-trait-impl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/union/union-trait-impl.rs')
-rw-r--r--tests/ui/union/union-trait-impl.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/ui/union/union-trait-impl.rs b/tests/ui/union/union-trait-impl.rs
new file mode 100644
index 00000000000..6134e91f31e
--- /dev/null
+++ b/tests/ui/union/union-trait-impl.rs
@@ -0,0 +1,19 @@
+// run-pass
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
+use std::fmt;
+
+union U {
+    a: u8
+}
+
+impl fmt::Display for U {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        unsafe { write!(f, "Oh hai {}", self.a) }
+    }
+}
+
+fn main() {
+    assert_eq!(U { a: 2 }.to_string(), "Oh hai 2");
+}