]> git.lizzy.rs Git - rust.git/blob - tests/target/closure.rs
Merge pull request #312 from marcusklaas/closure-fix
[rust.git] / tests / target / closure.rs
1 // Closures
2
3 fn main() {
4     let square = (|i: i32| i * i);
5
6     let commented = |// first
7                      a, // argument
8                      // second
9                      b: WithType, // argument
10                      // ignored
11                      _| {
12         (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
13     };
14
15     let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
16                            ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
17         xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
18     };
19
20     let loooooooooooooong_name = |field| {
21              // TODO(#27): format comments.
22         if field.node.attrs.len() > 0 {
23             field.node.attrs[0].span.lo
24         } else {
25             field.span.lo
26         }
27     };
28
29     let block_me = |field| {
30         if true_story() {
31             1
32         } else {
33             2
34         }
35     };
36
37     let unblock_me = |trivial| closure();
38
39     let empty = |arg| {};
40
41     let simple = |arg| { /* TODO(#27): comment formatting */
42         foo(arg)
43     };
44
45     let test = || {
46         do_something();
47         do_something_else();
48     };
49
50     let arg_test = |big_argument_name, test123| {
51         looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame()
52     };
53
54     let arg_test = |big_argument_name, test123| {
55         looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame()
56     };
57
58     let simple_closure = move || -> () {};
59
60     let closure = |input: Ty| -> Option<String> { foo() };
61
62     let closure_with_return_type = |aaaaaaaaaaaaaaaaaaaaaaarg1,
63                                     aaaaaaaaaaaaaaaaaaaaaaarg2|
64                                     -> Strong {
65         "sup".to_owned()
66     };
67
68     |arg1, arg2, _, _, arg3, arg4| {
69         let temp = arg4 + arg3;
70         arg2 * arg1 - temp
71     }
72 }
73
74 fn issue311() {
75     let func = |x| println!("{}", x);
76
77     (func)(0.0);
78 }