2015-08-19 22:39:45 +02:00
|
|
|
// Closures
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let square = (|i: i32| i * i);
|
|
|
|
|
|
|
|
let commented = |// first
|
|
|
|
a, // argument
|
|
|
|
// second
|
|
|
|
b: WithType, // argument
|
|
|
|
// ignored
|
|
|
|
_| {
|
2016-03-14 08:51:06 +01:00
|
|
|
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
|
2015-09-09 23:09:39 +02:00
|
|
|
};
|
2015-08-19 22:39:45 +02:00
|
|
|
|
|
|
|
let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
|
|
|
|
ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
|
2015-09-09 23:09:39 +02:00
|
|
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
|
|
|
};
|
2015-08-19 22:39:45 +02:00
|
|
|
|
|
|
|
let loooooooooooooong_name = |field| {
|
2015-10-19 21:41:47 +02:00
|
|
|
// TODO(#27): format comments.
|
2015-09-09 23:09:39 +02:00
|
|
|
if field.node.attrs.len() > 0 {
|
|
|
|
field.node.attrs[0].span.lo
|
|
|
|
} else {
|
|
|
|
field.span.lo
|
|
|
|
}
|
|
|
|
};
|
2015-08-19 22:39:45 +02:00
|
|
|
|
|
|
|
let block_me = |field| {
|
2015-09-09 23:09:39 +02:00
|
|
|
if true_story() {
|
|
|
|
1
|
|
|
|
} else {
|
|
|
|
2
|
|
|
|
}
|
|
|
|
};
|
2015-08-19 22:39:45 +02:00
|
|
|
|
|
|
|
let unblock_me = |trivial| closure();
|
|
|
|
|
|
|
|
let empty = |arg| {};
|
2015-08-20 22:08:51 +02:00
|
|
|
|
2015-10-19 21:41:47 +02:00
|
|
|
let simple = |arg| {
|
|
|
|
// TODO(#27): comment formatting
|
2015-09-11 00:53:21 +02:00
|
|
|
foo(arg)
|
|
|
|
};
|
2015-09-08 20:56:33 +02:00
|
|
|
|
2015-08-20 22:08:51 +02:00
|
|
|
let test = || {
|
2015-09-09 23:09:39 +02:00
|
|
|
do_something();
|
|
|
|
do_something_else();
|
|
|
|
};
|
2015-08-20 22:08:51 +02:00
|
|
|
|
2015-08-20 23:05:41 +02:00
|
|
|
let arg_test = |big_argument_name, test123| {
|
2015-09-09 23:09:39 +02:00
|
|
|
looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame()
|
|
|
|
};
|
2015-08-20 23:05:41 +02:00
|
|
|
|
|
|
|
let arg_test = |big_argument_name, test123| {
|
2015-09-09 23:09:39 +02:00
|
|
|
looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame()
|
|
|
|
};
|
2015-08-20 23:05:41 +02:00
|
|
|
|
2015-09-08 20:56:33 +02:00
|
|
|
let simple_closure = move || -> () {};
|
|
|
|
|
|
|
|
let closure = |input: Ty| -> Option<String> { foo() };
|
|
|
|
|
|
|
|
let closure_with_return_type = |aaaaaaaaaaaaaaaaaaaaaaarg1,
|
|
|
|
aaaaaaaaaaaaaaaaaaaaaaarg2|
|
|
|
|
-> Strong {
|
2015-09-11 00:53:21 +02:00
|
|
|
"sup".to_owned()
|
|
|
|
};
|
2015-09-08 20:56:33 +02:00
|
|
|
|
2015-08-20 22:08:51 +02:00
|
|
|
|arg1, arg2, _, _, arg3, arg4| {
|
|
|
|
let temp = arg4 + arg3;
|
|
|
|
arg2 * arg1 - temp
|
|
|
|
}
|
2015-08-19 22:39:45 +02:00
|
|
|
}
|
2015-09-12 14:31:51 +02:00
|
|
|
|
|
|
|
fn issue311() {
|
|
|
|
let func = |x| println!("{}", x);
|
|
|
|
|
|
|
|
(func)(0.0);
|
|
|
|
}
|