diff options
Diffstat (limited to 'src/test/ui/traits/coercion-generic.rs')
-rw-r--r-- | src/test/ui/traits/coercion-generic.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/ui/traits/coercion-generic.rs b/src/test/ui/traits/coercion-generic.rs new file mode 100644 index 000000000..bf4dda495 --- /dev/null +++ b/src/test/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"); +} |