]> git.lizzy.rs Git - rust.git/blobdiff - src/chains.rs
Remove BlockIndentStyle::Inherit
[rust.git] / src / chains.rs
index a2c69b2cb425a34b08e8cb0be7b607db04adf0df..32505138e6563e8e14263ef54829c524b3f4a719 100644 (file)
@@ -123,7 +123,7 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
                       parent_shape.block_indent(context.config.tab_spaces)),
          false)
     } else {
-        (chain_indent_newline(context, shape.add_offset(parent_rewrite.len())), false)
+        (shape.block_indent(context.config.tab_spaces), false)
     };
 
     let max_width = try_opt!((shape.width + shape.indent.width() + shape.offset)
@@ -135,7 +135,6 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
         let mut shape = try_opt!(parent_shape.shrink_left(last_line_width(&parent_rewrite)));
         match context.config.chain_indent {
             BlockIndentStyle::Visual => other_child_shape,
-            BlockIndentStyle::Inherit => shape,
             BlockIndentStyle::Tabbed => {
                 shape.offset = shape.offset.checked_sub(context.config.tab_spaces).unwrap_or(0);
                 shape.indent.block_indent += context.config.tab_spaces;
@@ -158,9 +157,9 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
                      .collect::<Option<Vec<_>>>());
 
     // Total of all items excluding the last.
-    let almost_total = rewrites[..rewrites.len() - 1]
-        .iter()
-        .fold(0, |a, b| a + first_line_width(b)) + parent_rewrite.len();
+    let almost_total = rewrites[..rewrites.len() - 1].iter().fold(0, |a, b| {
+        a + first_line_width(b)
+    }) + parent_rewrite.len();
 
     let veto_single_line = if subexpr_list.len() > context.config.chain_one_line_max - 1 {
         // -1 above because subexpr_list does not include the parent.
@@ -296,22 +295,10 @@ fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext) -> (ast::Expr,
 fn chain_indent(context: &RewriteContext, shape: Shape) -> Shape {
     match context.config.chain_indent {
         BlockIndentStyle::Visual => shape.visual_indent(0),
-        BlockIndentStyle::Inherit => shape.block_indent(0),
         BlockIndentStyle::Tabbed => shape.block_indent(context.config.tab_spaces),
     }
 }
 
-// Ignores visual indenting because this function should be called where it is
-// not possible to use visual indentation because we are starting on a newline.
-fn chain_indent_newline(context: &RewriteContext, shape: Shape) -> Shape {
-    match context.config.chain_indent {
-        BlockIndentStyle::Inherit => shape.block_indent(0),
-        BlockIndentStyle::Visual | BlockIndentStyle::Tabbed => {
-            shape.block_indent(context.config.tab_spaces)
-        }
-    }
-}
-
 fn rewrite_method_call_with_overflow(expr_kind: &ast::ExprKind,
                                      last: &mut String,
                                      almost_total: usize,
@@ -425,9 +412,8 @@ fn rewrite_method_call(method_name: ast::Ident,
     let (lo, type_str) = if types.is_empty() {
         (args[0].span.hi, String::new())
     } else {
-        let type_list: Vec<_> = try_opt!(types.iter()
-                                             .map(|ty| ty.rewrite(context, shape))
-                                             .collect());
+        let type_list: Vec<_> =
+            try_opt!(types.iter().map(|ty| ty.rewrite(context, shape)).collect());
 
         let type_str = if context.config.spaces_within_angle_brackets && type_list.len() > 0 {
             format!("::< {} >", type_list.join(", "))
@@ -435,7 +421,11 @@ fn rewrite_method_call(method_name: ast::Ident,
             format!("::<{}>", type_list.join(", "))
         };
 
-        (types.last().unwrap().span.hi, type_str)
+        (types.last()
+             .unwrap()
+             .span
+             .hi,
+         type_str)
     };
 
     let callee_str = format!(".{}{}", method_name, type_str);