Debian Codegraph @

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

raw
1 /* { dg-output "3\r*\n" } */
2 #[lang = "sized"]
3 pub trait Sized {}
4
5 extern "C" {
6 fn printf(s: *const i8, ...);
7 }
8
9 trait FnLike<A, R> {
10 fn call(&self, arg: A) -> R;
11 }
12
13 struct S;
14 impl<'a, T> FnLike<&'a T, &'a T> for S {
15 fn call(&self, arg: &'a T) -> &'a T {
16 // { dg-warning "unused name .self." "" { target *-*-* } .-1 }
17 arg
18 }
19 }
20
21 fn indirect<F>(f: F)
22 where
23 F: for<'a> FnLike<&'a isize, &'a isize>,
24 {
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 indirect(S);
39
40 0
41 }