about summary refs log tree commit diff
path: root/src/expr.rs
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2017-06-16 08:49:49 +0900
committertopecongiro <seuchida@gmail.com>2017-06-16 08:49:49 +0900
commit208ff15954c76ee0a7908e20eecb35dac6a69f72 (patch)
treecee4bda3ca2170a5da4a5cdbaf04de550b91eb67 /src/expr.rs
parentd3d31a9f75c99fac12beb1341610d806f56c5d31 (diff)
Format source codes
Diffstat (limited to 'src/expr.rs')
-rw-r--r--src/expr.rs74
1 files changed, 38 insertions, 36 deletions
diff --git a/src/expr.rs b/src/expr.rs
index 6bba83b520c..080fdca0f04 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -384,9 +384,8 @@ where
         // This is needed in case of line break not caused by a
         // shortage of space, but by end-of-line comments, for example.
         if !rhs_result.contains('\n') {
-            let lhs_shape = try_opt!(try_opt!(shape.offset_left(prefix.len())).sub_width(
-                infix.len(),
-            ));
+            let lhs_shape =
+                try_opt!(try_opt!(shape.offset_left(prefix.len())).sub_width(infix.len()));
             let lhs_result = lhs.rewrite(context, lhs_shape);
             if let Some(lhs_result) = lhs_result {
                 let mut result = format!("{}{}{}", prefix, lhs_result, infix);
@@ -475,9 +474,11 @@ where
     let nested_shape = match context.config.array_layout() {
         IndentStyle::Block => shape.block().block_indent(context.config.tab_spaces()),
         IndentStyle::Visual => {
-            try_opt!(shape.visual_indent(bracket_size).sub_width(
-                bracket_size * 2,
-            ))
+            try_opt!(
+                shape
+                    .visual_indent(bracket_size)
+                    .sub_width(bracket_size * 2)
+            )
         }
     };
 
@@ -500,9 +501,9 @@ where
         }
     }
 
-    let has_long_item = items.iter().any(|li| {
-        li.item.as_ref().map(|s| s.len() > 10).unwrap_or(false)
-    });
+    let has_long_item = items
+        .iter()
+        .any(|li| li.item.as_ref().map(|s| s.len() > 10).unwrap_or(false));
 
     let tactic = match context.config.array_layout() {
         IndentStyle::Block => {
@@ -1591,9 +1592,10 @@ impl Rewrite for ast::Arm {
             body.rewrite(context, body_shape),
             body_shape.width,
         ));
-        let indent_str = shape.indent.block_indent(context.config).to_string(
-            context.config,
-        );
+        let indent_str = shape
+            .indent
+            .block_indent(context.config)
+            .to_string(context.config);
         let (body_prefix, body_suffix) = if context.config.wrap_match_arms() {
             if context.config.match_block_trailing_comma() {
                 ("{", "},")
@@ -1655,13 +1657,13 @@ fn rewrite_guard(
     if let Some(ref guard) = *guard {
         // First try to fit the guard string on the same line as the pattern.
         // 4 = ` if `, 5 = ` => {`
-        if let Some(cond_shape) = shape.shrink_left(pattern_width + 4).and_then(
-            |s| s.sub_width(5),
-        )
+        if let Some(cond_shape) = shape
+            .shrink_left(pattern_width + 4)
+            .and_then(|s| s.sub_width(5))
         {
-            if let Some(cond_str) = guard.rewrite(context, cond_shape).and_then(|s| {
-                s.rewrite(context, cond_shape)
-            })
+            if let Some(cond_str) = guard
+                .rewrite(context, cond_shape)
+                .and_then(|s| s.rewrite(context, cond_shape))
             {
                 if !cond_str.contains('\n') {
                     return Some(format!(" if {}", cond_str));
@@ -1679,9 +1681,10 @@ fn rewrite_guard(
             if let Some(cond_str) = guard.rewrite(context, cond_shape) {
                 return Some(format!(
                     "\n{}if {}",
-                    shape.indent.block_indent(context.config).to_string(
-                        context.config,
-                    ),
+                    shape
+                        .indent
+                        .block_indent(context.config)
+                        .to_string(context.config),
                     cond_str
                 ));
             }
@@ -1713,9 +1716,8 @@ fn rewrite_pat_expr(
             } else {
                 format!("{} ", matcher)
             };
-            let pat_shape = try_opt!(try_opt!(shape.offset_left(matcher.len())).sub_width(
-                connector.len(),
-            ));
+            let pat_shape =
+                try_opt!(try_opt!(shape.offset_left(matcher.len())).sub_width(connector.len()));
             pat_string = try_opt!(pat.rewrite(context, pat_shape));
             format!("{}{}{}", matcher, pat_string, connector)
         }
@@ -1828,9 +1830,9 @@ where
             width: callee_max_width,
             ..shape
         };
-        let callee_str = callee.rewrite(context, callee_shape).ok_or(
-            Ordering::Greater,
-        )?;
+        let callee_str = callee
+            .rewrite(context, callee_shape)
+            .ok_or(Ordering::Greater)?;
 
         rewrite_call_inner(
             context,
@@ -1938,9 +1940,9 @@ where
         );
     }
 
-    let args_shape = shape.sub_width(last_line_width(&callee_str)).ok_or(
-        Ordering::Less,
-    )?;
+    let args_shape = shape
+        .sub_width(last_line_width(&callee_str))
+        .ok_or(Ordering::Less)?;
     Ok(format!(
         "{}{}",
         callee_str,
@@ -1956,9 +1958,8 @@ where
 
 fn need_block_indent(s: &str, shape: Shape) -> bool {
     s.lines().skip(1).any(|s| {
-        s.find(|c| !char::is_whitespace(c)).map_or(false, |w| {
-            w + 1 < shape.indent.width()
-        })
+        s.find(|c| !char::is_whitespace(c))
+            .map_or(false, |w| w + 1 < shape.indent.width())
     })
 }
 
@@ -2293,9 +2294,10 @@ fn rewrite_struct_lit<'a>(
         return Some(format!("{} {{}}", path_str));
     }
 
-    let field_iter = fields.into_iter().map(StructLitField::Regular).chain(
-        base.into_iter().map(StructLitField::Base),
-    );
+    let field_iter = fields
+        .into_iter()
+        .map(StructLitField::Regular)
+        .chain(base.into_iter().map(StructLitField::Base));
 
     // Foo { a: Foo } - indent is +3, width is -5.
     let (h_shape, v_shape) = try_opt!(struct_lit_shape(shape, context, path_str.len() + 3, 2));