Debian Codegraph @

gcc/testsuite/rust/compile/torture/issue-1555.rs

raw
1 #[lang = "sized"]
2 pub trait Sized {}
3
4 extern "C" {
5 fn printf(s: *const i8, ...);
6 }
7
8 struct Foo(i32);
9 trait Bar {
10 fn baz(&self);
11 }
12
13 trait Baz: Bar {
14 fn qux(&self);
15 }
16
17 impl Bar for Foo {
18 fn baz(&self) {
19 unsafe {
20 let a = "baz %i\n\0";
21 let b = a as *const str;
22 let c = b as *const i8;
23
24 printf(c, self.0);
25 }
26 }
27 }
28
29 impl Baz for Foo {
30 fn qux(&self) {
31 unsafe {
32 let a = "qux %i\n\0";
33 let b = a as *const str;
34 let c = b as *const i8;
35
36 printf(c, self.0);
37 }
38 }
39 }
40
41 fn static_dispatch<T: Baz>(t: &T) {
42 t.baz();
43 t.qux();
44 }
45
46 pub fn main() {
47 let a;
48 a = &Foo(123);
49
50 static_dispatch(a);
51 }