Debian Codegraph @

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

raw
1 /* { dg-output "parent123\r*\nchild\r*\n" } */
2
3 extern "C" {
4 fn printf(s: *const i8, ...);
5 }
6
7 #[lang = "sized"]
8 pub trait Sized {}
9
10 struct Foo(i32);
11 trait Parent {
12 fn parent(&self);
13 }
14
15 trait Child : Parent {
16 fn child(&self);
17 }
18
19 impl Parent for Foo {
20 fn parent(&self) {
21 unsafe {
22 let parent = "parent%i\n\0";
23 let msg = parent as *const str;
24 printf(msg as *const i8,self.0);
25 }
26 }
27 }
28
29 impl Child for Foo {
30 fn child(&self) {
31 let _ = self;
32 unsafe {
33 let child = "child\n\0";
34 let msg = child as *const str;
35 printf(msg as *const i8);
36 }
37 }
38 }
39
40 pub fn main() -> i32 {
41 let a = Foo(123);
42 let b: &dyn Child = &a;
43
44 b.parent();
45 b.child();
46 0
47 }