Add tests for async & async move
This commit is contained in:
parent
0b25f602fd
commit
fedde3790c
21
src/expr.rs
21
src/expr.rs
@ -345,17 +345,28 @@ pub fn format_expr(
|
||||
}
|
||||
// FIXME(#2743)
|
||||
ast::ExprKind::ObsoleteInPlace(..) => unimplemented!(),
|
||||
ast::ExprKind::Async(_capture_by, _node_id, ref block) => {
|
||||
if let rw @ Some(_) =
|
||||
rewrite_single_line_block(context, "async ", block, Some(&expr.attrs), None, shape)
|
||||
{
|
||||
ast::ExprKind::Async(capture_by, _node_id, ref block) => {
|
||||
let mover = if capture_by == ast::CaptureBy::Value {
|
||||
"move "
|
||||
} else {
|
||||
""
|
||||
};
|
||||
if let rw @ Some(_) = rewrite_single_line_block(
|
||||
context,
|
||||
format!("{}{}", "async ", mover).as_str(),
|
||||
block,
|
||||
Some(&expr.attrs),
|
||||
None,
|
||||
shape,
|
||||
) {
|
||||
rw
|
||||
} else {
|
||||
// 6 = `async `
|
||||
let budget = shape.width.saturating_sub(6);
|
||||
Some(format!(
|
||||
"{}{}",
|
||||
"{}{}{}",
|
||||
"async ",
|
||||
mover,
|
||||
rewrite_block(
|
||||
block,
|
||||
Some(&expr.attrs),
|
||||
|
@ -239,9 +239,9 @@ impl<'a> FnSig<'a> {
|
||||
// Vis defaultness constness unsafety abi.
|
||||
result.push_str(&*format_visibility(context, &self.visibility));
|
||||
result.push_str(format_defaultness(self.defaultness));
|
||||
result.push_str(format_asyncness(self.asyncness));
|
||||
result.push_str(format_constness(self.constness));
|
||||
result.push_str(format_unsafety(self.unsafety));
|
||||
result.push_str(format_asyncness(self.asyncness));
|
||||
result.push_str(&format_abi(
|
||||
self.abi,
|
||||
context.config.force_explicit_abi(),
|
||||
|
7
tests/source/async_block.rs
Normal file
7
tests/source/async_block.rs
Normal file
@ -0,0 +1,7 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
|
||||
fn main() {
|
||||
let x = async {
|
||||
Ok(())
|
||||
};
|
||||
}
|
15
tests/source/async_fn.rs
Normal file
15
tests/source/async_fn.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
|
||||
async fn bar() -> Result<(), ()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn baz() -> Result<(), ()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
unsafe async fn foo() {
|
||||
async move {
|
||||
Ok(())
|
||||
}
|
||||
}
|
5
tests/target/async_block.rs
Normal file
5
tests/target/async_block.rs
Normal file
@ -0,0 +1,5 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
|
||||
fn main() {
|
||||
let x = async { Ok(()) };
|
||||
}
|
13
tests/target/async_fn.rs
Normal file
13
tests/target/async_fn.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// rustfmt-edition: Edition2018
|
||||
|
||||
async fn bar() -> Result<(), ()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn baz() -> Result<(), ()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
unsafe async fn foo() {
|
||||
async move { Ok(()) }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user