about summary refs log tree commit diff
path: root/tests/ui/traits/coercion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/traits/coercion.rs')
-rw-r--r--tests/ui/traits/coercion.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/ui/traits/coercion.rs b/tests/ui/traits/coercion.rs
new file mode 100644
index 00000000000..e62742bac5c
--- /dev/null
+++ b/tests/ui/traits/coercion.rs
@@ -0,0 +1,35 @@
+// run-pass
+#![allow(dead_code)]
+#![allow(unused_mut)]
+#![allow(unused_variables)]
+
+use std::io::{self, Write};
+
+trait Trait {
+    fn f(&self);
+}
+
+#[derive(Copy, Clone)]
+struct Struct {
+    x: isize,
+    y: isize,
+}
+
+impl Trait for Struct {
+    fn f(&self) {
+        println!("Hi!");
+    }
+}
+
+fn foo(mut a: Box<dyn Write>) {}
+
+pub fn main() {
+    let a = Struct { x: 1, y: 2 };
+    let b: Box<dyn Trait> = Box::new(a);
+    b.f();
+    let c: &dyn Trait = &a;
+    c.f();
+
+    let out = io::stdout();
+    foo(Box::new(out));
+}