aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/compile/trait14.rs
blob: c1d42b5d6bb9300354e8100bc7b8fa2f9cf7775a (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Testing diamond problem with supertraits

 
struct Foo {
    my_int: u32,
}

trait GrandParent {
    fn grandparent(&self);
}

trait Parent1 : GrandParent {
    fn parent1(&self);
}

trait Parent2 : GrandParent {
    fn parent2(&self);
}

trait Child : Parent1+Parent2 {
    fn child(&self);
}

impl GrandParent for Foo {
    fn grandparent(&self) { let _ = self; }
}

impl Parent1 for Foo {
    fn parent1(&self) { let _ = self; }
}

impl Parent2 for Foo {
    fn parent2(&self) { let _ = self; }
}

impl Child for Foo {
    fn child(&self) {
        let _ = self;
    }
}

pub fn main() {
    let a = Foo{my_int: 0xf00dfeed};
    let b: &dyn Child = &a;

    b.parent1();
    b.child();

    // Suppress bogus compile warning
    let _ = a.my_int;
}