summaryrefslogtreecommitdiffstats
path: root/src/test/ui/traits/coercion-generic.rs
blob: bf4dda49519107cef0b14585479d001d6b9d3f64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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");
}