]> git.lizzy.rs Git - rust.git/blobdiff - src/expr.rs
discard trailing blank comments
[rust.git] / src / expr.rs
index 8118e3bccfd6f11525dc47b65b5e0eb3a85d5805..0f4474d7c0f1a363420d394ad596288e0d05d39b 100644 (file)
@@ -345,8 +345,38 @@ fn needs_space_after_range(rhs: &ast::Expr) -> bool {
         }
         // 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
@@ -1167,17 +1197,11 @@ pub fn rewrite_multiple_patterns(
             shape.width,
         )
     };
-    let fmt = ListFormatting {
-        tactic,
-        separator: " |",
-        trailing_separator: SeparatorTactic::Never,
-        separator_place: context.config.binop_separator(),
-        shape,
-        ends_with_newline: false,
-        preserve_newline: false,
-        nested: false,
-        config: context.config,
-    };
+    let fmt = ListFormatting::new(shape, context.config)
+        .tactic(tactic)
+        .separator(" |")
+        .separator_place(context.config.binop_separator())
+        .ends_with_newline(false);
     write_list(&items, &fmt)
 }
 
@@ -1730,17 +1754,9 @@ fn rewrite_tuple_in_visual_indent_style<'a, T>(
         Separator::Comma,
         nested_shape.width,
     );
-    let fmt = ListFormatting {
-        tactic,
-        separator: ",",
-        trailing_separator: SeparatorTactic::Never,
-        separator_place: SeparatorPlace::Back,
-        shape,
-        ends_with_newline: false,
-        preserve_newline: false,
-        nested: false,
-        config: context.config,
-    };
+    let fmt = ListFormatting::new(shape, context.config)
+        .tactic(tactic)
+        .ends_with_newline(false);
     let list_str = write_list(&item_vec, &fmt)?;
 
     Some(format!("({})", list_str))