Debian Codegraph @

gcc/testsuite/rust/execute/torture/trait18.rs

raw
1 /* { dg-output "parent\r*\nchild\r*\n" } */
2 //Testing default implementations with supertraits.
3
4 extern "C" {
5 fn printf(s: *const i8, ...);
6 }
7
8 struct Foo {
9 my_int: u32,
10 }
11
12 trait Parent {
13 fn parent_str(&self) -> &'static str;
14 fn parent(&self) {
15 unsafe {
16 let parent: &'static str = self.parent_str();
17 let msg = parent as *const str;
18 printf(msg as *const i8);
19 }
20 }
21 }
22
23 trait Child : Parent {
24 fn child(&self);
25 }
26
27 impl Parent for Foo {
28 fn parent_str(&self) -> &'static str {
29 let _ = self;
30 return "parent\n\0";
31 }
32 }
33
34 impl Child for Foo {
35 fn child(&self) {
36 let _ = self;
37 unsafe {
38 let child = "child\n\0";
39 let msg = child as *const str;
40 printf(msg as *const i8);
41 }
42 }
43 }
44
45 pub fn main() -> i32 {
46 let a = Foo{ my_int: 0xfeedf00d};
47 let b: &dyn Child = &a;
48
49 b.parent();
50 b.child();
51
52 // Bogus warning silencer
53 let _ = a.my_int;
54
55 0
56 }