2017-01-15 19:50:27 -06:00
|
|
|
// rustfmt-normalize_comments: true
|
2015-08-19 15:39:45 -05:00
|
|
|
// Closures
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let square = (|i: i32| i * i);
|
|
|
|
|
2016-11-20 13:37:35 -06:00
|
|
|
let commented =
|
|
|
|
|// first
|
|
|
|
a, // argument
|
|
|
|
// second
|
|
|
|
b: WithType, // argument
|
|
|
|
// ignored
|
|
|
|
_| (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
|
2015-08-19 15:39:45 -05:00
|
|
|
|
|
|
|
let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
|
|
|
|
ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
|
2015-09-09 16:09:39 -05:00
|
|
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
|
|
|
};
|
2015-08-19 15:39:45 -05:00
|
|
|
|
|
|
|
let loooooooooooooong_name = |field| {
|
2016-05-29 10:58:38 -05:00
|
|
|
// format comments.
|
2015-09-09 16:09:39 -05:00
|
|
|
if field.node.attrs.len() > 0 {
|
|
|
|
field.node.attrs[0].span.lo
|
|
|
|
} else {
|
|
|
|
field.span.lo
|
|
|
|
}
|
|
|
|
};
|
2015-08-19 15:39:45 -05:00
|
|
|
|
|
|
|
let unblock_me = |trivial| closure();
|
|
|
|
|
|
|
|
let empty = |arg| {};
|
2015-08-20 15:08:51 -05:00
|
|
|
|
2015-10-19 14:41:47 -05:00
|
|
|
let simple = |arg| {
|
2016-05-29 10:58:38 -05:00
|
|
|
// comment formatting
|
2015-09-10 17:53:21 -05:00
|
|
|
foo(arg)
|
|
|
|
};
|
2015-09-08 13:56:33 -05:00
|
|
|
|
2015-08-20 15:08:51 -05:00
|
|
|
let test = || {
|
2015-09-09 16:09:39 -05:00
|
|
|
do_something();
|
|
|
|
do_something_else();
|
|
|
|
};
|
2015-08-20 15:08:51 -05:00
|
|
|
|
2016-05-12 14:50:43 -05:00
|
|
|
let arg_test =
|
|
|
|
|big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
|
2015-08-20 16:05:41 -05:00
|
|
|
|
2016-05-12 14:50:43 -05:00
|
|
|
let arg_test =
|
|
|
|
|big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
|
2015-08-20 16:05:41 -05:00
|
|
|
|
2015-09-08 13:56:33 -05:00
|
|
|
let simple_closure = move || -> () {};
|
|
|
|
|
|
|
|
let closure = |input: Ty| -> Option<String> { foo() };
|
|
|
|
|
2016-05-12 14:50:43 -05:00
|
|
|
let closure_with_return_type =
|
|
|
|
|aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };
|
2015-09-08 13:56:33 -05:00
|
|
|
|
2015-08-20 15:08:51 -05:00
|
|
|
|arg1, arg2, _, _, arg3, arg4| {
|
|
|
|
let temp = arg4 + arg3;
|
|
|
|
arg2 * arg1 - temp
|
|
|
|
}
|
2015-08-19 15:39:45 -05:00
|
|
|
}
|
2015-09-12 07:31:51 -05:00
|
|
|
|
|
|
|
fn issue311() {
|
|
|
|
let func = |x| println!("{}", x);
|
|
|
|
|
|
|
|
(func)(0.0);
|
|
|
|
}
|
2016-04-13 15:36:59 -05:00
|
|
|
|
|
|
|
fn issue863() {
|
|
|
|
let closure = |x| match x {
|
|
|
|
0 => true,
|
|
|
|
_ => false,
|
|
|
|
} == true;
|
|
|
|
}
|
2016-04-15 03:52:08 -05:00
|
|
|
|
|
|
|
fn issue934() {
|
|
|
|
let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
|
|
|
|
let mut h = SpanlessHash::new(cx);
|
|
|
|
h.hash_block(block);
|
|
|
|
h.finish()
|
|
|
|
};
|
|
|
|
|
|
|
|
let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
|
|
|
|
let mut h = SpanlessHash::new(cx);
|
|
|
|
h.hash_block(block);
|
|
|
|
h.finish();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
|
|
|
|
pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
|
|
|
|
match (&left.node, &right.node) {
|
|
|
|
(&ExprBinary(l_op, ref ll, ref lr), &ExprBinary(r_op, ref rl, ref rr)) => {
|
|
|
|
l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr) ||
|
|
|
|
swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
|
|
|
|
l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|