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