about summary refs log tree commit diff
path: root/src/expr.rs
diff options
context:
space:
mode:
authorNick Cameron <nrc@ncameron.org>2018-07-31 08:52:07 +1200
committerGitHub <noreply@github.com>2018-07-31 08:52:07 +1200
commit3c20d8a9e626eda5ecc283542735e708f3a84959 (patch)
treeafc23d221ab5f3ea5488449da4ebca0f67258970 /src/expr.rs
parentdc209cc97fac89c5ab6fdd5214098b2799c4c661 (diff)
parent46b241004dbc4d6f77e81868304af4e79df9fe6f (diff)
Merge pull request #2874 from cavedweller/master
Format Async block and async fn
Diffstat (limited to 'src/expr.rs')
-rw-r--r--src/expr.rs34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 8118e3bccfd..72cf618dca5 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -345,8 +345,38 @@ pub fn format_expr(
         }
         // FIXME(#2743)
         ast::ExprKind::ObsoleteInPlace(..) => unimplemented!(),
-        // FIXME(topecongiro) Format async block.
-        ast::ExprKind::Async(..) => None,
+        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),
+                        None,
+                        context,
+                        Shape::legacy(budget, shape.indent)
+                    )?
+                ))
+            }
+        }
     };
 
     expr_rw