gccrs: Add execution test cases
[official-gcc.git] / gcc / testsuite / rust / execute / torture / issue-1496.rs
blob9f08b2ae98acd43b84c7697f7206eca1e5acbee6
1 /* { dg-output "foo_deref\nimm_deref\n123\n" } */
2 extern "C" {
3     fn printf(s: *const i8, ...);
6 #[lang = "deref"]
7 pub trait Deref {
8     type Target;
10     fn deref(&self) -> &Self::Target;
13 impl<T> Deref for &T {
14     type Target = T;
16     fn deref(&self) -> &T {
17         unsafe {
18             let a = "imm_deref\n\0";
19             let b = a as *const str;
20             let c = b as *const i8;
22             printf(c);
23         }
25         *self
26     }
29 impl<T> Deref for &mut T {
30     type Target = T;
32     fn deref(&self) -> &T {
33         unsafe {
34             let a = "mut_deref\n\0";
35             let b = a as *const str;
36             let c = b as *const i8;
38             printf(c);
39         }
41         *self
42     }
45 struct Foo<T>(T);
46 impl<T> Deref for Foo<T> {
47     type Target = T;
49     fn deref(&self) -> &Self::Target {
50         unsafe {
51             let a = "foo_deref\n\0";
52             let b = a as *const str;
53             let c = b as *const i8;
55             printf(c);
56         }
58         &self.0
59     }
62 fn main() -> i32 {
63     let foo = Foo(123);
64     let bar = &foo as &i32;
66     unsafe {
67         let a = "%i\n\0";
68         let b = a as *const str;
69         let c = b as *const i8;
71         printf(c, *bar);
72     }
74     0