Debian Codegraph @

gcc/testsuite/rust/execute/torture/closure2.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 #[lang = "fn_once"]
10 pub trait FnOnce<Args> {
11 #[lang = "fn_once_output"]
12 type Output;
13
14 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
15 }
16
17 fn f<F: FnOnce(i32) -> i32>(g: F) {
18 let call = g(1);
19 unsafe {
20 let a = "%i\n\0";
21 let b = a as *const str;
22 let c = b as *const i8;
23
24 printf(c, call);
25 }
26 }
27
28 pub fn main() -> i32 {
29 let a = |i: i32| {
30 let b = i + 2;
31 b
32 };
33 f(a);
34 0
35 }