Skip to content

Commit

Permalink
Add tests for async & async move
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrittain committed Jul 29, 2018
1 parent 0b25f60 commit fedde37
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/expr.rs
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/items.rs
Expand Up @@ -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(),
Expand Down
7 changes: 7 additions & 0 deletions tests/source/async_block.rs
@@ -0,0 +1,7 @@
// rustfmt-edition: Edition2018

fn main() {
let x = async {
Ok(())
};
}
15 changes: 15 additions & 0 deletions tests/source/async_fn.rs
@@ -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 changes: 5 additions & 0 deletions tests/target/async_block.rs
@@ -0,0 +1,5 @@
// rustfmt-edition: Edition2018

fn main() {
let x = async { Ok(()) };
}
13 changes: 13 additions & 0 deletions tests/target/async_fn.rs
@@ -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(()) }
}

0 comments on commit fedde37

Please sign in to comment.