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);
|
|
|
|
|
2017-06-11 23:01:41 -05: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 {
|
2017-08-19 13:47:40 -05:00
|
|
|
field.node.attrs[0].span.lo()
|
2015-09-09 16:09:39 -05:00
|
|
|
} else {
|
2017-08-19 13:47:40 -05:00
|
|
|
field.span.lo()
|
2015-09-09 16:09:39 -05:00
|
|
|
}
|
|
|
|
};
|
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
|
2017-10-27 01:39:15 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
let block_body_with_comment = args.iter().map(|a| {
|
|
|
|
// Emitting only dep-info is possible only for final crate type, as
|
|
|
|
// as others may emit required metadata for dependent crate types
|
|
|
|
if a.starts_with("--emit") && is_final_crate_type && !self.workspace_mode {
|
|
|
|
"--emit=dep-info"
|
|
|
|
} else {
|
|
|
|
a
|
|
|
|
}
|
|
|
|
});
|
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 {
|
2017-04-15 04:42:45 -05:00
|
|
|
let mut h = SpanlessHash::new(cx);
|
|
|
|
h.hash_block(block);
|
|
|
|
h.finish()
|
|
|
|
};
|
2016-04-15 03:52:08 -05:00
|
|
|
|
|
|
|
let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
|
2017-04-15 04:42:45 -05:00
|
|
|
let mut h = SpanlessHash::new(cx);
|
|
|
|
h.hash_block(block);
|
|
|
|
h.finish();
|
|
|
|
};
|
2016-04-15 03:52:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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)) => {
|
2017-09-14 22:20:58 -05:00
|
|
|
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)| {
|
2017-06-11 23:01:41 -05:00
|
|
|
l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
|
|
|
|
})
|
2016-04-15 03:52:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-20 17:23:59 -05:00
|
|
|
|
|
|
|
fn foo() {
|
|
|
|
lifetimes_iter___map(|lasdfasfd| {
|
2017-06-11 23:01:41 -05:00
|
|
|
let hi = if l.bounds.is_empty() {
|
2017-08-19 13:47:40 -05:00
|
|
|
l.lifetime.span.hi()
|
2017-06-11 23:01:41 -05:00
|
|
|
};
|
|
|
|
});
|
2017-03-20 17:23:59 -05:00
|
|
|
}
|
2017-05-02 21:26:31 -05:00
|
|
|
|
|
|
|
fn issue1405() {
|
|
|
|
open_raw_fd(fd, b'r').and_then(|file| {
|
2017-12-18 18:41:05 -06:00
|
|
|
Capture::new_raw(None, |_, err| unsafe { raw::pcap_fopen_offline(file, err) })
|
2017-05-02 21:26:31 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue1466() {
|
|
|
|
let vertex_buffer = frame.scope(|ctx| {
|
|
|
|
let buffer = ctx.create_host_visible_buffer::<VertexBuffer<Vertex>>(&vertices);
|
|
|
|
ctx.create_device_local_buffer(buffer)
|
|
|
|
});
|
|
|
|
}
|
2017-05-03 23:52:35 -05:00
|
|
|
|
|
|
|
fn issue470() {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{
|
2018-07-11 21:05:50 -05:00
|
|
|
let explicit_arg_decls =
|
|
|
|
explicit_arguments
|
|
|
|
.into_iter()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(index, (ty, pattern))| {
|
|
|
|
let lvalue = Lvalue::Arg(index as u32);
|
|
|
|
block = this.pattern(
|
|
|
|
block,
|
|
|
|
argument_extent,
|
|
|
|
hair::PatternRef::Hair(pattern),
|
|
|
|
&lvalue,
|
|
|
|
);
|
|
|
|
ArgDecl { ty: ty }
|
|
|
|
});
|
2017-05-03 23:52:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-06 23:06:54 -05:00
|
|
|
|
|
|
|
// #1509
|
|
|
|
impl Foo {
|
|
|
|
pub fn bar(&self) {
|
|
|
|
Some(SomeType {
|
2017-06-11 23:01:41 -05:00
|
|
|
push_closure_out_to_100_chars: iter(otherwise_it_works_ok.into_iter().map(|f| Ok(f))),
|
|
|
|
})
|
2017-05-06 23:06:54 -05:00
|
|
|
}
|
|
|
|
}
|
2017-05-07 16:44:48 -05:00
|
|
|
|
|
|
|
fn issue1329() {
|
|
|
|
aaaaaaaaaaaaaaaa
|
|
|
|
.map(|x| {
|
2017-06-11 23:01:41 -05:00
|
|
|
x += 1;
|
|
|
|
x
|
2018-07-11 21:05:50 -05:00
|
|
|
}).filter
|
2017-05-07 16:44:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue325() {
|
2017-12-18 18:41:05 -06:00
|
|
|
let f =
|
|
|
|
|| unsafe { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx };
|
2017-05-07 16:44:48 -05:00
|
|
|
}
|
2017-06-16 04:58:15 -05:00
|
|
|
|
|
|
|
fn issue1697() {
|
|
|
|
Test.func_a(
|
|
|
|
A_VERY_LONG_CONST_VARIABLE_NAME,
|
|
|
|
move |arg1, arg2, arg3, arg4| arg1 + arg2 + arg3 + arg4,
|
|
|
|
)
|
|
|
|
}
|
2017-06-16 16:25:58 -05:00
|
|
|
|
|
|
|
fn issue1694() {
|
|
|
|
foooooo(
|
|
|
|
|_referencefffffffff: _, _target_reference: _, _oid: _, _target_oid: _| {
|
|
|
|
format!("refs/pull/{}/merge", pr_id)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2017-06-18 22:07:20 -05:00
|
|
|
|
|
|
|
fn issue1713() {
|
|
|
|
rayon::join(
|
|
|
|
|| recurse(left, is_less, pred, limit),
|
|
|
|
|| recurse(right, is_less, Some(pivot), limit),
|
|
|
|
);
|
|
|
|
|
|
|
|
rayon::join(
|
|
|
|
1,
|
|
|
|
|| recurse(left, is_less, pred, limit),
|
|
|
|
2,
|
|
|
|
|| recurse(right, is_less, Some(pivot), limit),
|
|
|
|
);
|
|
|
|
}
|
2017-10-16 10:12:22 -05:00
|
|
|
|
|
|
|
fn issue2063() {
|
|
|
|
|ctx: Ctx<(String, String)>| -> io::Result<Response> {
|
|
|
|
Ok(Response::new().with_body(ctx.params.0))
|
|
|
|
}
|
|
|
|
}
|
2017-11-12 21:51:28 -06:00
|
|
|
|
|
|
|
fn issue1524() {
|
|
|
|
let f = |x| x;
|
|
|
|
let f = |x| x;
|
|
|
|
let f = |x| x;
|
|
|
|
let f = |x| x;
|
|
|
|
let f = |x| x;
|
|
|
|
}
|
2017-11-20 01:38:15 -06:00
|
|
|
|
|
|
|
fn issue2171() {
|
|
|
|
foo(|| unsafe {
|
|
|
|
if PERIPHERALS {
|
|
|
|
loop {}
|
|
|
|
} else {
|
|
|
|
PERIPHERALS = true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-11-29 15:10:50 -06:00
|
|
|
|
|
|
|
fn issue2207() {
|
|
|
|
a.map(|_| {
|
|
|
|
unsafe { a_very_very_very_very_very_very_very_long_function_name_or_anything_else() }
|
|
|
|
.to_string()
|
|
|
|
})
|
|
|
|
}
|
2017-12-10 06:19:51 -06:00
|
|
|
|
|
|
|
fn issue2262() {
|
|
|
|
result
|
|
|
|
.init(&mut result.slave.borrow_mut(), &mut (result.strategy)())
|
|
|
|
.map_err(|factory| Error {
|
|
|
|
factory,
|
|
|
|
slave: None,
|
|
|
|
})?;
|
|
|
|
}
|