about summary refs log tree commit diff
path: root/src/expr.rs
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2017-05-24 00:07:02 +0900
committertopecongiro <seuchida@gmail.com>2017-05-24 00:07:02 +0900
commit04bb5d892978b868a953bce4153dde66e583c7f4 (patch)
treecfe1a19edcee492dcf014135f7b2603870f90692 /src/expr.rs
parent92b54d6490fc638a136c07b42921ba7ff67743fa (diff)
Format source codes
Diffstat (limited to 'src/expr.rs')
-rw-r--r--src/expr.rs36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 885577b304e..29edb0a3e3f 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -98,16 +98,20 @@ fn format_expr(expr: &ast::Expr,
         }
         ast::ExprKind::Tup(ref items) => rewrite_tuple(context, items, expr.span, shape),
         ast::ExprKind::While(ref cond, ref block, label) => {
-            ControlFlow::new_while(None, cond, block, label, expr.span).rewrite(context, shape)
+            ControlFlow::new_while(None, cond, block, label, expr.span)
+                .rewrite(context, shape)
         }
         ast::ExprKind::WhileLet(ref pat, ref cond, ref block, label) => {
-            ControlFlow::new_while(Some(pat), cond, block, label, expr.span).rewrite(context, shape)
+            ControlFlow::new_while(Some(pat), cond, block, label, expr.span)
+                .rewrite(context, shape)
         }
         ast::ExprKind::ForLoop(ref pat, ref cond, ref block, label) => {
-            ControlFlow::new_for(pat, cond, block, label, expr.span).rewrite(context, shape)
+            ControlFlow::new_for(pat, cond, block, label, expr.span)
+                .rewrite(context, shape)
         }
         ast::ExprKind::Loop(ref block, label) => {
-            ControlFlow::new_loop(block, label, expr.span).rewrite(context, shape)
+            ControlFlow::new_loop(block, label, expr.span)
+                .rewrite(context, shape)
         }
         ast::ExprKind::Block(ref block) => block.rewrite(context, shape),
         ast::ExprKind::If(ref cond, ref if_block, ref else_block) => {
@@ -175,11 +179,12 @@ fn format_expr(expr: &ast::Expr,
         ast::ExprKind::Mac(ref mac) => {
             // Failure to rewrite a marco should not imply failure to
             // rewrite the expression.
-            rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
-                wrap_str(context.snippet(expr.span),
-                         context.config.max_width(),
-                         shape)
-            })
+            rewrite_macro(mac, None, context, shape, MacroPosition::Expression)
+                .or_else(|| {
+                             wrap_str(context.snippet(expr.span),
+                                      context.config.max_width(),
+                                      shape)
+                         })
         }
         ast::ExprKind::Ret(None) => {
             wrap_str("return".to_owned(), context.config.max_width(), shape)
@@ -319,7 +324,8 @@ pub fn rewrite_pair<LHS, RHS>(lhs: &LHS,
                                   .checked_sub(shape.used_width() + prefix.len() + infix.len()));
     let rhs_shape = match context.config.control_style() {
         Style::Default => {
-            try_opt!(shape.sub_width(suffix.len() + prefix.len())).visual_indent(prefix.len())
+            try_opt!(shape.sub_width(suffix.len() + prefix.len()))
+                .visual_indent(prefix.len())
         }
         Style::Rfc => try_opt!(shape.block_left(context.config.tab_spaces())),
     };
@@ -510,7 +516,8 @@ fn rewrite_closure(capture: ast::CaptureBy,
 
     // 1 = space between `|...|` and body.
     let extra_offset = extra_offset(&prefix, shape) + 1;
-    let body_shape = try_opt!(shape.sub_width(extra_offset)).add_offset(extra_offset);
+    let body_shape = try_opt!(shape.sub_width(extra_offset))
+        .add_offset(extra_offset);
 
     if let ast::ExprKind::Block(ref block) = body.node {
         // The body of the closure is an empty block.
@@ -852,8 +859,8 @@ impl<'a> ControlFlow<'a> {
 
             let new_width = try_opt!(new_width.checked_sub(if_str.len()));
             let else_expr = &else_node.stmts[0];
-            let else_str =
-                try_opt!(else_expr.rewrite(context, Shape::legacy(new_width, Indent::empty())));
+            let else_str = try_opt!(else_expr.rewrite(context,
+                                                      Shape::legacy(new_width, Indent::empty())));
 
             if if_str.contains('\n') || else_str.contains('\n') {
                 return None;
@@ -1790,11 +1797,11 @@ fn rewrite_call_args(context: &RewriteContext,
 
 fn can_be_overflowed(context: &RewriteContext, args: &[ptr::P<ast::Expr>]) -> bool {
     match args.last().map(|x| &x.node) {
-        Some(&ast::ExprKind::Block(..)) |
         Some(&ast::ExprKind::Match(..)) => {
             (context.config.fn_call_style() == IndentStyle::Block && args.len() == 1) ||
             (context.config.fn_call_style() == IndentStyle::Visual && args.len() > 1)
         }
+        Some(&ast::ExprKind::Block(..)) |
         Some(&ast::ExprKind::Closure(..)) => {
             context.config.fn_call_style() == IndentStyle::Block ||
             context.config.fn_call_style() == IndentStyle::Visual && args.len() > 1
@@ -1821,6 +1828,7 @@ fn is_extendable(args: &[ptr::P<ast::Expr>]) -> bool {
         }
     } else if args.len() > 1 {
         match args[args.len() - 1].node {
+            ast::ExprKind::Block(..) |
             ast::ExprKind::Closure(..) |
             ast::ExprKind::Tup(..) => true,
             _ => false,