Debian Codegraph @

gcc/testsuite/rust/compile/trait14.rs

raw
1 // Testing diamond problem with supertraits
2
3
4 struct Foo {
5 my_int: u32,
6 }
7
8 trait GrandParent {
9 fn grandparent(&self);
10 }
11
12 trait Parent1 : GrandParent {
13 fn parent1(&self);
14 }
15
16 trait Parent2 : GrandParent {
17 fn parent2(&self);
18 }
19
20 trait Child : Parent1+Parent2 {
21 fn child(&self);
22 }
23
24 impl GrandParent for Foo {
25 fn grandparent(&self) { let _ = self; }
26 }
27
28 impl Parent1 for Foo {
29 fn parent1(&self) { let _ = self; }
30 }
31
32 impl Parent2 for Foo {
33 fn parent2(&self) { let _ = self; }
34 }
35
36 impl Child for Foo {
37 fn child(&self) {
38 let _ = self;
39 }
40 }
41
42 pub fn main() {
43 let a = Foo{my_int: 0xf00dfeed};
44 let b: &dyn Child = &a;
45
46 b.parent1();
47 b.child();
48
49 // Suppress bogus compile warning
50 let _ = a.my_int;
51 }