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