Debian Codegraph @

gcc/testsuite/rust/execute/torture/trait9.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 struct S;
14 impl<T> FnLike<&T, &T> for S {
15 fn call(&self, arg: &T) -> &T {
16 // { dg-warning "unused name .self." "" { target *-*-* } .-1 }
17 arg
18 }
19 }
20
21 fn indirect<F: FnLike<&isize, &isize>>(f: F) {
22 let x = 3;
23 let y = f.call(&x);
24
25 unsafe {
26 let a = "%i\n\0";
27 let b = a as *const str;
28 let c = b as *const i8;
29
30 printf(c, *y);
31 }
32 }
33
34 fn main() -> i32 {
35 indirect(S);
36
37 0
38 }