]> git.lizzy.rs Git - rust.git/blob - tests/target/closure.rs
update Serde, etc.
[rust.git] / tests / target / closure.rs
1 // Closures
2
3 fn main() {
4     let square = (|i: i32| i * i);
5
6     let commented =
7         |// first
8          a, // argument
9          // second
10          b: WithType, // argument
11          // ignored
12          _| (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
13
14     let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
15                            ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
16         xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
17     };
18
19     let loooooooooooooong_name = |field| {
20         // format comments.
21         if field.node.attrs.len() > 0 {
22             field.node.attrs[0].span.lo
23         } else {
24             field.span.lo
25         }
26     };
27
28     let unblock_me = |trivial| closure();
29
30     let empty = |arg| {};
31
32     let simple = |arg| {
33         // comment formatting
34         foo(arg)
35     };
36
37     let test = || {
38         do_something();
39         do_something_else();
40     };
41
42     let arg_test =
43         |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
44
45     let arg_test =
46         |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
47
48     let simple_closure = move || -> () {};
49
50     let closure = |input: Ty| -> Option<String> { foo() };
51
52     let closure_with_return_type =
53         |aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };
54
55     |arg1, arg2, _, _, arg3, arg4| {
56         let temp = arg4 + arg3;
57         arg2 * arg1 - temp
58     }
59 }
60
61 fn issue311() {
62     let func = |x| println!("{}", x);
63
64     (func)(0.0);
65 }
66
67 fn issue863() {
68     let closure = |x| match x {
69         0 => true,
70         _ => false,
71     } == true;
72 }
73
74 fn issue934() {
75     let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
76         let mut h = SpanlessHash::new(cx);
77         h.hash_block(block);
78         h.finish()
79     };
80
81     let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
82         let mut h = SpanlessHash::new(cx);
83         h.hash_block(block);
84         h.finish();
85     };
86 }
87
88 impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
89     pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
90         match (&left.node, &right.node) {
91             (&ExprBinary(l_op, ref ll, ref lr), &ExprBinary(r_op, ref rl, ref rr)) => {
92                 l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr) ||
93                 swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
94                     l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
95                 })
96             }
97         }
98     }
99 }