Add tests for async & async move

This commit is contained in:
Ben Brittain 2018-07-29 08:45:31 -07:00
parent 0b25f602fd
commit fedde3790c
6 changed files with 57 additions and 6 deletions

View File

@ -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),

View File

@ -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(),

View File

@ -0,0 +1,7 @@
// rustfmt-edition: Edition2018
fn main() {
let x = async {
Ok(())
};
}

15
tests/source/async_fn.rs Normal file
View 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(())
}
}

View File

@ -0,0 +1,5 @@
// rustfmt-edition: Edition2018
fn main() {
let x = async { Ok(()) };
}

13
tests/target/async_fn.rs Normal file
View 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(()) }
}