]> git.lizzy.rs Git - rust.git/blob - tests/run-pass/closures.rs
9b6e2966648777424b5a39bb80700e7880d29bea
[rust.git] / tests / run-pass / closures.rs
1 #![crate_type = "lib"]
2 #![feature(custom_attribute)]
3 #![allow(dead_code, unused_attributes)]
4
5 #[miri_run]
6 fn simple() -> i32 {
7     let y = 10;
8     let f = |x| x + y;
9     f(2)
10 }
11
12 #[miri_run]
13 fn crazy_closure() -> (i32, i32, i32) {
14     fn inner<T: Copy>(t: T) -> (i32, T, T) {
15         struct NonCopy;
16         let x = NonCopy;
17
18         let a = 2;
19         let b = 40;
20         let f = move |y, z, asdf| {
21             drop(x);
22             (a + b + y + z, asdf, t)
23         };
24         f(a, b, t)
25     }
26
27     inner(10)
28 }
29
30 // #[miri_run]
31 // fn closure_arg_adjustment_problem() -> i64 {
32 //     fn once<F: FnOnce(i64)>(f: F) { f(2); }
33 //     let mut y = 1;
34 //     {
35 //         let f = |x| y += x;
36 //         once(f);
37 //     }
38 //     y
39 // }