Debian Codegraph @

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

raw
1 /* { dg-output "3\r*\n" } */
2 extern "C" {
3 fn printf(s: *const i8, ...);
4 }
5
6 #[lang = "sized"]
7 pub trait Sized {}
8
9 trait FnLike<A, R> {
10 fn call(&self, arg: A) -> R;
11 }
12
13 type FnObject<'b> = dyn for<'a> FnLike<&'a isize, &'a isize> + 'b;
14
15 struct Identity;
16
17 impl<'a, T> FnLike<&'a T, &'a T> for Identity {
18 fn call(&self, arg: &'a T) -> &'a T {
19 // { dg-warning "unused name .self." "" { target *-*-* } .-1 }
20 arg
21 }
22 }
23
24 fn call_repeatedly(f: &FnObject) {
25 let x = 3;
26 let y = f.call(&x);
27
28 unsafe {
29 let a = "%i\n\0";
30 let b = a as *const str;
31 let c = b as *const i8;
32
33 printf(c, *y);
34 }
35 }
36
37 fn main() -> i32 {
38 call_repeatedly(&Identity);
39
40 0
41 }