Debian Codegraph @

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

raw
1 /* { dg-output "parent123\r*\nchild\r*\n" } */
2 // Testing generics passing with supertraits
3
4 extern "C" {
5 fn printf(s: *const i8, ...);
6 }
7
8 #[lang = "sized"]
9 pub trait Sized {}
10
11 struct Foo {
12 my_int: u32,
13 }
14
15 trait Parent<T> {
16 fn parent(&self) -> T;
17 }
18
19 trait Child<T> : Parent<T> {
20 fn child(&self);
21 }
22
23 impl Parent<u32> for Foo {
24 fn parent(&self) -> u32 {
25 unsafe {
26 let parent = "parent%i\n\0";
27 let msg = parent as *const str;
28 printf(msg as *const i8,self.my_int);
29 return self.my_int;
30 }
31 }
32 }
33
34 impl Child<u32> 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: 123};
47 let b: &dyn Child<u32> = &a;
48
49 b.parent();
50 b.child();
51
52 //Silence bogus warning
53 let _ = a.my_int;
54
55 0
56 }