Debian Codegraph @

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

raw
1 // { dg-additional-options "-w" }
2
3 #[lang = "sized"]
4 pub trait Sized {}
5
6 extern "C" {
7 fn printf(s: *const i8, ...);
8 }
9
10 #[lang = "deref"]
11 pub trait Deref {
12 type Target;
13
14 fn deref(&self) -> &Self::Target;
15 }
16
17 impl<T> Deref for &T {
18 type Target = T;
19
20 fn deref(&self) -> &T {
21 unsafe {
22 let a = "imm_deref\n\0";
23 let b = a as *const str;
24 let c = b as *const i8;
25
26 printf(c);
27 }
28
29 *self
30 }
31 }
32
33 impl<T> Deref for &mut T {
34 type Target = T;
35
36 fn deref(&self) -> &T {
37 unsafe {
38 let a = "mut_deref\n\0";
39 let b = a as *const str;
40 let c = b as *const i8;
41
42 printf(c);
43 }
44
45 *self
46 }
47 }
48
49 struct Foo<T>(T);
50 impl<T> Deref for Foo<T> {
51 type Target = T;
52
53 fn deref(&self) -> &Self::Target {
54 unsafe {
55 let a = "foo_deref\n\0";
56 let b = a as *const str;
57 let c = b as *const i8;
58
59 printf(c);
60 }
61
62 &self.0
63 }
64 }
65
66 struct Bar(i32);
67 impl Bar {
68 fn cake(self) -> i32 {
69 self.0 + 1
70 }
71 }
72
73 pub fn main() {
74 let foo: Foo<Bar> = Foo(Bar(123));
75 let bar: Bar = *foo;
76
77 let cake_result: i32 = foo.cake();
78 }