about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPavel Sountsov <siege@google.com>2015-09-18 21:50:44 -0700
committerSiegeLord <slabode@aim.com>2015-09-19 10:36:45 -0700
commit03e1b2782616cbc8f06ba4e484b1540ae23e32be (patch)
tree7d62f4cb04b59eb355fc69278f13e5dcb267bae5 /src
parentd4108a3029cecf7855514f568f8b3b88edcbfdb7 (diff)
Add Indent::none(), remove make_indent.
Diffstat (limited to 'src')
-rw-r--r--src/chains.rs4
-rw-r--r--src/comment.rs5
-rw-r--r--src/expr.rs48
-rw-r--r--src/items.rs54
-rw-r--r--src/lib.rs22
-rw-r--r--src/lists.rs6
-rw-r--r--src/missed_spans.rs3
-rw-r--r--src/rewrite.rs2
-rw-r--r--src/string.rs4
-rw-r--r--src/utils.rs6
-rw-r--r--src/visitor.rs20
11 files changed, 82 insertions, 92 deletions
diff --git a/src/chains.rs b/src/chains.rs
index daf800ace08..c59638d9e50 100644
--- a/src/chains.rs
+++ b/src/chains.rs
@@ -21,7 +21,7 @@
 
 use Indent;
 use rewrite::{Rewrite, RewriteContext};
-use utils::{first_line_width, make_indent};
+use utils::first_line_width;
 use expr::rewrite_call;
 
 use syntax::{ast, ptr};
@@ -117,7 +117,7 @@ pub fn rewrite_chain(mut expr: &ast::Expr,
     let connector = if fits_single_line {
         String::new()
     } else {
-        format!("\n{}", make_indent(indent, context.config))
+        format!("\n{}", indent.to_string(context.config))
     };
 
     let first_connector = if extend {
diff --git a/src/comment.rs b/src/comment.rs
index 683bf4b650c..765d61cfa11 100644
--- a/src/comment.rs
+++ b/src/comment.rs
@@ -15,7 +15,6 @@ use std::iter;
 use Indent;
 use config::Config;
 use string::{StringFormat, rewrite_string};
-use utils::make_indent;
 
 pub fn rewrite_comment(orig: &str,
                        block_style: bool,
@@ -45,7 +44,7 @@ pub fn rewrite_comment(orig: &str,
         config: config,
     };
 
-    let indent_str = make_indent(offset, config);
+    let indent_str = offset.to_string(config);
     let line_breaks = s.chars().filter(|&c| c == '\n').count();
 
     let (_, mut s) = s.lines()
@@ -304,7 +303,7 @@ mod test {
         assert_eq!("/* test */", rewrite_comment(" //test", true, 100, Indent::new(0, 100),
                                                  &config));
         assert_eq!("// comment\n// on a", rewrite_comment("// comment on a", false, 10,
-                                                          Indent::new(0, 0), &config));
+                                                          Indent::empty(), &config));
 
         assert_eq!("//  A multi line comment\n            // between args.",
                    rewrite_comment("//  A multi line comment\n             // between args.",
diff --git a/src/expr.rs b/src/expr.rs
index 3e8401af8b9..74d5522cc59 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -15,8 +15,7 @@ use Indent;
 use rewrite::{Rewrite, RewriteContext};
 use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTactic};
 use string::{StringFormat, rewrite_string};
-use utils::{span_after, make_indent, extra_offset, first_line_width, last_line_width, wrap_str,
-            binary_search};
+use utils::{span_after, extra_offset, first_line_width, last_line_width, wrap_str, binary_search};
 use visitor::FmtVisitor;
 use config::{StructLitStyle, MultilineStyle};
 use comment::{FindUncommented, rewrite_comment, contains_comment};
@@ -268,7 +267,7 @@ fn rewrite_closure(capture: ast::CaptureClause,
     if !ret_str.is_empty() {
         if prefix.contains('\n') {
             prefix.push('\n');
-            prefix.push_str(&make_indent(argument_offset, context.config));
+            prefix.push_str(&argument_offset.to_string(context.config));
         } else {
             prefix.push(' ');
         }
@@ -311,12 +310,12 @@ fn rewrite_closure(capture: ast::CaptureClause,
                            .as_ref()
                            .and_then(|body_expr| {
                                if let ast::Expr_::ExprBlock(ref inner) = body_expr.node {
-                                   Some(inner.rewrite(&context, 2, Indent::new(0, 0)))
+                                   Some(inner.rewrite(&context, 2, Indent::empty()))
                                } else {
                                    None
                                }
                            })
-                           .unwrap_or_else(|| body.rewrite(&context, 2, Indent::new(0, 0)));
+                           .unwrap_or_else(|| body.rewrite(&context, 2, Indent::empty()));
 
     Some(format!("{} {}", prefix, try_opt!(body_rewrite)))
 }
@@ -592,11 +591,11 @@ fn single_line_if_else(context: &RewriteContext,
 
         let new_width = try_opt!(width.checked_sub(pat_expr_str.len() + fixed_cost));
         let if_expr = if_node.expr.as_ref().unwrap();
-        let if_str = try_opt!(if_expr.rewrite(context, new_width, Indent::new(0, 0)));
+        let if_str = try_opt!(if_expr.rewrite(context, new_width, Indent::empty()));
 
         let new_width = try_opt!(new_width.checked_sub(if_str.len()));
         let else_expr = else_node.expr.as_ref().unwrap();
-        let else_str = try_opt!(else_expr.rewrite(context, new_width, Indent::new(0, 0)));
+        let else_str = try_opt!(else_expr.rewrite(context, new_width, Indent::empty()));
 
         // FIXME: this check shouldn't be necessary. Rewrites should either fail
         // or wrap to a newline when the object does not fit the width.
@@ -638,7 +637,7 @@ fn rewrite_match(context: &RewriteContext,
 
     let nested_context = context.nested_context();
     let arm_indent = nested_context.block_indent + context.overflow_indent;
-    let arm_indent_str = make_indent(arm_indent, context.config);
+    let arm_indent_str = arm_indent.to_string(context.config);
 
     let open_brace_pos = span_after(mk_sp(cond.span.hi, arm_start_pos(&arms[0])),
                                     "{",
@@ -688,7 +687,7 @@ fn rewrite_match(context: &RewriteContext,
     // match expression, but meh.
 
     result.push('\n');
-    result.push_str(&make_indent(context.block_indent + context.overflow_indent, context.config));
+    result.push_str(&(context.block_indent + context.overflow_indent).to_string(context.config));
     result.push('}');
     Some(result)
 }
@@ -710,7 +709,7 @@ fn arm_end_pos(arm: &ast::Arm) -> BytePos {
 impl Rewrite for ast::Arm {
     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
         let &ast::Arm { ref attrs, ref pats, ref guard, ref body } = self;
-        let indent_str = make_indent(offset, context.config);
+        let indent_str = offset.to_string(context.config);
 
         // FIXME this is all a bit grotty, would be nice to abstract out the
         // treatment of attributes.
@@ -738,7 +737,7 @@ impl Rewrite for ast::Arm {
                                     .map(|p| {
                                         p.rewrite(context,
                                                   pat_budget,
-                                                  offset.block_indent(context.config.tab_spaces))
+                                                  offset.block_indent(context.config))
                                     })
                                     .collect::<Option<Vec<_>>>());
 
@@ -784,7 +783,7 @@ impl Rewrite for ast::Arm {
 
         let mut line_indent = offset + pats_width;
         if vertical {
-            line_indent = line_indent.block_indent(context.config.tab_spaces);
+            line_indent = line_indent.block_indent(context.config);
         }
 
         let comma = if let ast::ExprBlock(_) = body.node {
@@ -819,7 +818,7 @@ impl Rewrite for ast::Arm {
         Some(format!("{}{} =>\n{}{},",
                      attr_str.trim_left(),
                      pats_str,
-                     make_indent(offset.block_indent(context.config.tab_spaces), context.config),
+                     offset.block_indent(context.config).to_string(context.config),
                      body_str))
     }
 }
@@ -849,11 +848,10 @@ fn rewrite_guard(context: &RewriteContext,
         if overhead < width {
             let cond_str = guard.rewrite(context,
                                          width - overhead,
-                                         offset.block_indent(context.config.tab_spaces));
+                                         offset.block_indent(context.config));
             if let Some(cond_str) = cond_str {
                 return Some(format!("\n{}if {}",
-                                    make_indent(offset.block_indent(context.config.tab_spaces),
-                                                context.config),
+                                    offset.block_indent(context.config).to_string(context.config),
                                     cond_str));
             }
         }
@@ -908,7 +906,7 @@ fn rewrite_pat_expr(context: &RewriteContext,
 
     // The expression won't fit on the current line, jump to next.
     result.push('\n');
-    result.push_str(&make_indent(pat_offset, context.config));
+    result.push_str(&pat_offset.to_string(context.config));
 
     let expr_rewrite = expr.rewrite(context,
                                     context.config.max_width - pat_offset.width(),
@@ -1067,7 +1065,7 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
         StructLitStyle::Block => {
             // If we are all on one line, then we'll ignore the indent, and we
             // have a smaller budget.
-            let indent = context.block_indent.block_indent(context.config.tab_spaces);
+            let indent = context.block_indent.block_indent(context.config);
             let v_budget = context.config.max_width.checked_sub(indent.width()).unwrap_or(0);
             (indent, v_budget)
         }
@@ -1139,10 +1137,10 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
     let fields_str = try_opt!(write_list(&items.collect::<Vec<_>>(), &fmt));
 
     let format_on_newline = || {
-        let inner_indent = make_indent(context.block_indent
-                                              .block_indent(context.config.tab_spaces),
-                                       context.config);
-        let outer_indent = make_indent(context.block_indent, context.config);
+        let inner_indent = context.block_indent
+                                  .block_indent(context.config)
+                                  .to_string(context.config);
+        let outer_indent = context.block_indent.to_string(context.config);
         Some(format!("{} {{\n{}{}\n{}}}", path_str, inner_indent, fields_str, outer_indent))
     };
 
@@ -1255,7 +1253,7 @@ fn rewrite_binary_op(context: &RewriteContext,
     Some(format!("{} {}\n{}{}",
                  try_opt!(lhs.rewrite(context, budget, offset)),
                  operator_str,
-                 make_indent(offset, context.config),
+                 offset.to_string(context.config),
                  rhs_result))
 }
 
@@ -1319,8 +1317,8 @@ pub fn rewrite_assign_rhs<S: Into<String>>(context: &RewriteContext,
         None => {
             // Expression did not fit on the same line as the identifier. Retry
             // on the next line.
-            let new_offset = offset.block_indent(context.config.tab_spaces);
-            result.push_str(&format!("\n{}", make_indent(new_offset, context.config)));
+            let new_offset = offset.block_indent(context.config);
+            result.push_str(&format!("\n{}", new_offset.to_string(context.config)));
 
             // FIXME: we probably should related max_width to width instead of config.max_width
             // where is the 1 coming from anyway?
diff --git a/src/items.rs b/src/items.rs
index ae55fdf4c29..e72251815cf 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -11,8 +11,7 @@
 // Formatting top-level items - functions, structs, enums, traits, impls.
 
 use Indent;
-use utils::{format_mutability, format_visibility, make_indent, contains_skip, span_after,
-            end_typaram, wrap_str};
+use utils::{format_mutability, format_visibility, contains_skip, span_after, end_typaram, wrap_str};
 use lists::{write_list, itemize_list, ListItem, ListFormatting, SeparatorTactic, ListTactic};
 use expr::rewrite_assign_rhs;
 use comment::FindUncommented;
@@ -35,7 +34,7 @@ impl<'a> FmtVisitor<'a> {
 
             if let Some(ref ty) = local.ty {
                 infix.push_str(": ");
-                infix.push_str(&ty.rewrite(&self.get_context(), 1000, Indent::new(0, 0)).unwrap());
+                infix.push_str(&ty.rewrite(&self.get_context(), 1000, Indent::empty()).unwrap());
             }
 
             if local.init.is_some() {
@@ -126,7 +125,7 @@ impl<'a> FmtVisitor<'a> {
         // this.
         if newline_brace {
             result.push('\n');
-            result.push_str(&make_indent(indent, self.config));
+            result.push_str(&indent.to_string(self.config));
         } else {
             result.push(' ');
         }
@@ -226,17 +225,17 @@ impl<'a> FmtVisitor<'a> {
         if one_line_budget <= 0 {
             if self.config.fn_args_paren_newline {
                 result.push('\n');
-                result.push_str(&make_indent(arg_indent, self.config));
+                result.push_str(&arg_indent.to_string(self.config));
                 arg_indent = arg_indent + 1; // extra space for `(`
                 result.push('(');
             } else {
                 result.push_str("(\n");
-                result.push_str(&make_indent(arg_indent, self.config));
+                result.push_str(&arg_indent.to_string(self.config));
             }
         } else if self.config.fn_args_layout == StructLitStyle::Block {
-            arg_indent = indent.block_indent(self.config.tab_spaces);
+            arg_indent = indent.block_indent(self.config);
             result.push_str("(\n");
-            result.push_str(&make_indent(arg_indent, self.config));
+            result.push_str(&arg_indent.to_string(self.config));
         } else {
             result.push('(');
         }
@@ -281,7 +280,7 @@ impl<'a> FmtVisitor<'a> {
                 };
 
                 result.push('\n');
-                result.push_str(&make_indent(indent, self.config));
+                result.push_str(&indent.to_string(self.config));
             } else {
                 result.push(' ');
             }
@@ -390,7 +389,7 @@ impl<'a> FmtVisitor<'a> {
 
         let indent = match self.config.fn_arg_indent {
             BlockIndentStyle::Inherit => indent,
-            BlockIndentStyle::Tabbed => indent.block_indent(self.config.tab_spaces),
+            BlockIndentStyle::Tabbed => indent.block_indent(self.config),
             BlockIndentStyle::Visual => arg_indent,
         };
 
@@ -444,7 +443,7 @@ impl<'a> FmtVisitor<'a> {
 
         // Didn't work. we must force vertical layout and put args on a newline.
         if let None = budgets {
-            let new_indent = indent.block_indent(self.config.tab_spaces);
+            let new_indent = indent.block_indent(self.config);
             let used_space = new_indent.width() + 2; // account for `(` and `)`
             let max_space = self.config.ideal_width + self.config.leeway;
             if used_space > max_space {
@@ -480,14 +479,13 @@ impl<'a> FmtVisitor<'a> {
         let generics_str = self.format_generics(generics,
                                                 " {",
                                                 self.block_indent,
-                                                self.block_indent
-                                                    .block_indent(self.config.tab_spaces),
+                                                self.block_indent.block_indent(self.config),
                                                 codemap::mk_sp(span.lo, body_start))
                                .unwrap();
         self.buffer.push_str(&generics_str);
 
         self.last_pos = body_start;
-        self.block_indent = self.block_indent.block_indent(self.config.tab_spaces);
+        self.block_indent = self.block_indent.block_indent(self.config);
         for (i, f) in enum_def.variants.iter().enumerate() {
             let next_span_start: BytePos = if i == enum_def.variants.len() - 1 {
                 span.hi
@@ -497,7 +495,7 @@ impl<'a> FmtVisitor<'a> {
 
             self.visit_variant(f, i == enum_def.variants.len() - 1, next_span_start);
         }
-        self.block_indent = self.block_indent.block_unindent(self.config.tab_spaces);
+        self.block_indent = self.block_indent.block_unindent(self.config);
 
         self.format_missing_with_indent(span.lo + BytePos(enum_snippet.rfind('}').unwrap() as u32),
                                         self.config);
@@ -530,7 +528,7 @@ impl<'a> FmtVisitor<'a> {
                                                  arg.ty
                                                     .rewrite(&self.get_context(),
                                                              1000,
-                                                             Indent::new(0, 0))
+                                                             Indent::empty())
                                                     .unwrap()
                                              },
                                              span_after(field.span, "(", self.codemap),
@@ -672,7 +670,7 @@ impl<'a> FmtVisitor<'a> {
                          single_line_cost as usize + used_budget > self.config.max_width;
 
         let tactic = if break_line {
-            let indentation = make_indent(offset.block_indent(self.config.tab_spaces), self.config);
+            let indentation = offset.block_indent(self.config).to_string(self.config);
             result.push('\n');
             result.push_str(&indentation);
 
@@ -687,7 +685,7 @@ impl<'a> FmtVisitor<'a> {
             tactic: tactic,
             separator: ",",
             trailing_separator: self.config.struct_trailing_comma,
-            indent: offset.block_indent(self.config.tab_spaces),
+            indent: offset.block_indent(self.config),
             h_width: self.config.max_width,
             v_width: budget,
             ends_with_newline: true,
@@ -699,7 +697,7 @@ impl<'a> FmtVisitor<'a> {
 
         if break_line {
             result.push('\n');
-            result.push_str(&make_indent(offset, self.config));
+            result.push_str(&offset.to_string(self.config));
         }
 
         result.push_str(terminator);
@@ -751,7 +749,7 @@ impl<'a> FmtVisitor<'a> {
                                                                       Density::Tall,
                                                                       span.hi));
             result.push_str(&where_clause_str);
-            result.push_str(&make_indent(self.block_indent, self.config));
+            result.push_str(&self.block_indent.to_string(self.config));
             result.push('\n');
             result.push_str(opener.trim());
         } else {
@@ -776,9 +774,9 @@ impl<'a> FmtVisitor<'a> {
             ast::StructFieldKind::UnnamedField(vis) => format_visibility(vis),
         };
         // FIXME silly width, indent
-        let typ = field.node.ty.rewrite(&self.get_context(), 1000, Indent::new(0, 0)).unwrap();
+        let typ = field.node.ty.rewrite(&self.get_context(), 1000, Indent::empty()).unwrap();
 
-        let indent = self.block_indent + self.config.tab_spaces;
+        let indent = self.block_indent.block_indent(self.config);
         let mut attr_str = field.node
                                 .attrs
                                 .rewrite(&self.get_context(),
@@ -787,7 +785,7 @@ impl<'a> FmtVisitor<'a> {
                                 .unwrap();
         if !attr_str.is_empty() {
             attr_str.push('\n');
-            attr_str.push_str(&make_indent(indent, self.config));
+            attr_str.push_str(&indent.to_string(self.config));
         }
 
         match name {
@@ -812,7 +810,7 @@ impl<'a> FmtVisitor<'a> {
 
         let offset = match self.config.generics_indent {
             BlockIndentStyle::Inherit => offset,
-            BlockIndentStyle::Tabbed => offset.block_indent(self.config.tab_spaces),
+            BlockIndentStyle::Tabbed => offset.block_indent(self.config),
             // 1 = <
             BlockIndentStyle::Visual => generics_offset + 1,
         };
@@ -870,7 +868,7 @@ impl<'a> FmtVisitor<'a> {
         }
 
         let extra_indent = match self.config.where_indent {
-            BlockIndentStyle::Inherit => Indent::new(0, 0),
+            BlockIndentStyle::Inherit => Indent::empty(),
             BlockIndentStyle::Tabbed | BlockIndentStyle::Visual => Indent::new(config.tab_spaces,
                                                                                0),
         };
@@ -879,7 +877,7 @@ impl<'a> FmtVisitor<'a> {
 
         let offset = match self.config.where_pred_indent {
             BlockIndentStyle::Inherit => indent + extra_indent,
-            BlockIndentStyle::Tabbed => indent + extra_indent.block_indent(config.tab_spaces),
+            BlockIndentStyle::Tabbed => indent + extra_indent.block_indent(config),
             // 6 = "where ".len()
             BlockIndentStyle::Visual => indent + extra_indent + 6,
         };
@@ -915,9 +913,7 @@ impl<'a> FmtVisitor<'a> {
         // 9 = " where ".len() + " {".len()
         if density == Density::Tall || preds_str.contains('\n') ||
            indent.width() + 9 + preds_str.len() > self.config.max_width {
-            Some(format!("\n{}where {}",
-                         make_indent(indent + extra_indent, self.config),
-                         preds_str))
+            Some(format!("\n{}where {}", (indent + extra_indent).to_string(self.config), preds_str))
         } else {
             Some(format!(" where {}", preds_str))
         }
diff --git a/src/lib.rs b/src/lib.rs
index 2ca206665e2..30150537309 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -83,7 +83,10 @@ const SKIP_ANNOTATION: &'static str = "rustfmt_skip";
 
 #[derive(Copy, Clone, Debug)]
 pub struct Indent {
+    // Width of the block indent, in characters. Must be a multiple of
+    // Config::tab_spaces.
     block_indent: usize,
+    // Alignment in characters.
     alignment: usize,
 }
 
@@ -92,13 +95,17 @@ impl Indent {
         Indent { block_indent: block_indent, alignment: alignment }
     }
 
-    pub fn block_indent(mut self, block_indent: usize) -> Indent {
-        self.block_indent += block_indent;
+    pub fn empty() -> Indent {
+        Indent::new(0, 0)
+    }
+
+    pub fn block_indent(mut self, config: &Config) -> Indent {
+        self.block_indent += config.tab_spaces;
         self
     }
 
-    pub fn block_unindent(mut self, block_indent: usize) -> Indent {
-        self.block_indent -= block_indent;
+    pub fn block_unindent(mut self, config: &Config) -> Indent {
+        self.block_indent -= config.tab_spaces;
         self
     }
 
@@ -139,10 +146,7 @@ impl Sub for Indent {
     type Output = Indent;
 
     fn sub(self, rhs: Indent) -> Indent {
-        Indent {
-            block_indent: self.block_indent - rhs.block_indent,
-            alignment: self.alignment - rhs.alignment,
-        }
+        Indent::new(self.block_indent - rhs.block_indent, self.alignment - rhs.alignment)
     }
 }
 
@@ -150,7 +154,7 @@ impl Add<usize> for Indent {
     type Output = Indent;
 
     fn add(self, rhs: usize) -> Indent {
-        Indent { block_indent: self.block_indent, alignment: self.alignment + rhs }
+        Indent::new(self.block_indent, self.alignment + rhs)
     }
 }
 
diff --git a/src/lists.rs b/src/lists.rs
index 40da7af198e..e00e8b0ee37 100644
--- a/src/lists.rs
+++ b/src/lists.rs
@@ -14,7 +14,7 @@ use std::iter::Peekable;
 use syntax::codemap::{self, CodeMap, BytePos};
 
 use Indent;
-use utils::{round_up_to_power_of_two, make_indent, wrap_str};
+use utils::{round_up_to_power_of_two, wrap_str};
 use comment::{FindUncommented, rewrite_comment, find_comment_end};
 use config::Config;
 
@@ -155,7 +155,7 @@ pub fn write_list<'b>(items: &[ListItem], formatting: &ListFormatting<'b>) -> Op
     let mut result = String::with_capacity(round_up_to_power_of_two(alloc_width));
 
     let mut line_len = 0;
-    let indent_str = &make_indent(formatting.indent, formatting.config);
+    let indent_str = &formatting.indent.to_string(formatting.config);
     for (i, item) in items.iter().enumerate() {
         let first = i == 0;
         let last = i == items.len() - 1;
@@ -221,7 +221,7 @@ pub fn write_list<'b>(items: &[ListItem], formatting: &ListFormatting<'b>) -> Op
             let formatted_comment = rewrite_comment(comment,
                                                     true,
                                                     formatting.v_width,
-                                                    Indent::new(0, 0),
+                                                    Indent::empty(),
                                                     formatting.config);
 
             result.push(' ');
diff --git a/src/missed_spans.rs b/src/missed_spans.rs
index c8da3e76b63..f39480f5450 100644
--- a/src/missed_spans.rs
+++ b/src/missed_spans.rs
@@ -9,7 +9,6 @@
 // except according to those terms.
 
 use config::Config;
-use utils::make_indent;
 use visitor::FmtVisitor;
 
 use syntax::codemap::{self, BytePos};
@@ -29,7 +28,7 @@ impl<'a> FmtVisitor<'a> {
                                           // No new lines in the snippet.
                                           this.buffer.push_str("\n");
                                       }
-                                      let indent = make_indent(this.block_indent, config);
+                                      let indent = this.block_indent.to_string(config);
                                       this.buffer.push_str(&indent);
                                   })
     }
diff --git a/src/rewrite.rs b/src/rewrite.rs
index 2e0f5691d2e..6517bbdf37b 100644
--- a/src/rewrite.rs
+++ b/src/rewrite.rs
@@ -44,7 +44,7 @@ impl<'a> RewriteContext<'a> {
         RewriteContext {
             codemap: self.codemap,
             config: self.config,
-            block_indent: self.block_indent.block_indent(self.config.tab_spaces),
+            block_indent: self.block_indent.block_indent(self.config),
             overflow_indent: self.overflow_indent,
         }
     }
diff --git a/src/string.rs b/src/string.rs
index 3da0a5f4a25..4e40b8e9ede 100644
--- a/src/string.rs
+++ b/src/string.rs
@@ -15,7 +15,7 @@ use regex::Regex;
 
 use Indent;
 use config::Config;
-use utils::{make_indent, round_up_to_power_of_two};
+use utils::round_up_to_power_of_two;
 
 use MIN_STRING;
 
@@ -39,7 +39,7 @@ pub fn rewrite_string<'a>(s: &str, fmt: &StringFormat<'a>) -> String {
 
     let graphemes = UnicodeSegmentation::graphemes(&*stripped_str, false).collect::<Vec<&str>>();
 
-    let indent = make_indent(fmt.offset, fmt.config);
+    let indent = fmt.offset.to_string(fmt.config);
     let indent = &indent;
 
     let mut cur_start = 0;
diff --git a/src/utils.rs b/src/utils.rs
index 3843e75973e..171572ccfbf 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -15,7 +15,6 @@ use syntax::codemap::{CodeMap, Span, BytePos};
 
 use Indent;
 use comment::FindUncommented;
-use config::Config;
 use rewrite::{Rewrite, RewriteContext};
 
 use SKIP_ANNOTATION;
@@ -38,11 +37,6 @@ pub fn span_after(original: Span, needle: &str, codemap: &CodeMap) -> BytePos {
 }
 
 #[inline]
-pub fn make_indent(indent: Indent, config: &Config) -> String {
-    indent.to_string(config)
-}
-
-#[inline]
 pub fn format_visibility(vis: Visibility) -> &'static str {
     match vis {
         Visibility::Public => "pub ",
diff --git a/src/visitor.rs b/src/visitor.rs
index d0a5df12221..5426d9bae90 100644
--- a/src/visitor.rs
+++ b/src/visitor.rs
@@ -102,7 +102,7 @@ impl<'a, 'v> visit::Visitor<'v> for FmtVisitor<'a> {
         };
 
         self.last_pos = self.last_pos + brace_compensation;
-        self.block_indent = self.block_indent.block_indent(self.config.tab_spaces);
+        self.block_indent = self.block_indent.block_indent(self.config);
         self.buffer.push_str("{");
 
         for stmt in &b.stmts {
@@ -117,7 +117,7 @@ impl<'a, 'v> visit::Visitor<'v> for FmtVisitor<'a> {
             None => {}
         }
 
-        self.block_indent = self.block_indent.block_unindent(self.config.tab_spaces);
+        self.block_indent = self.block_indent.block_unindent(self.config);
         // TODO: we should compress any newlines here to just one
         self.format_missing_with_indent(b.span.hi - brace_compensation, self.config);
         self.buffer.push_str("}");
@@ -198,9 +198,9 @@ impl<'a, 'v> visit::Visitor<'v> for FmtVisitor<'a> {
             }
             ast::Item_::ItemImpl(..) |
             ast::Item_::ItemTrait(..) => {
-                self.block_indent = self.block_indent.block_indent(self.config.tab_spaces);
+                self.block_indent = self.block_indent.block_indent(self.config);
                 visit::walk_item(self, item);
-                self.block_indent = self.block_indent.block_unindent(self.config.tab_spaces);
+                self.block_indent = self.block_indent.block_unindent(self.config);
             }
             ast::Item_::ItemExternCrate(_) => {
                 self.format_missing_with_indent(item.span.lo, self.config);
@@ -330,17 +330,17 @@ impl<'a> FmtVisitor<'a> {
 
         if is_internal {
             debug!("FmtVisitor::format_mod: internal mod");
-            self.block_indent = self.block_indent.block_indent(self.config.tab_spaces);
+            self.block_indent = self.block_indent.block_indent(self.config);
             visit::walk_mod(self, m);
             debug!("... last_pos after: {:?}", self.last_pos);
-            self.block_indent = self.block_indent.block_unindent(self.config.tab_spaces);
+            self.block_indent = self.block_indent.block_unindent(self.config);
         }
     }
 
     pub fn format_separate_mod(&mut self, m: &ast::Mod, filename: &str) {
         let filemap = self.codemap.get_filemap(filename);
         self.last_pos = filemap.start_pos;
-        self.block_indent = Indent::new(0, 0);
+        self.block_indent = Indent::empty();
         visit::walk_mod(self, m);
         self.format_missing(filemap.end_pos);
     }
@@ -353,7 +353,7 @@ impl<'a> FmtVisitor<'a> {
             codemap: self.codemap,
             config: self.config,
             block_indent: self.block_indent,
-            overflow_indent: Indent::new(0, 0),
+            overflow_indent: Indent::empty(),
         };
         // 1 = ";"
         match vp.rewrite(&context, self.config.max_width - offset.width() - 1, offset) {
@@ -385,7 +385,7 @@ impl<'a> FmtVisitor<'a> {
             codemap: self.codemap,
             config: self.config,
             block_indent: self.block_indent,
-            overflow_indent: Indent::new(0, 0),
+            overflow_indent: Indent::empty(),
         }
     }
 }
@@ -396,7 +396,7 @@ impl<'a> Rewrite for [ast::Attribute] {
         if self.is_empty() {
             return Some(result);
         }
-        let indent = utils::make_indent(offset, context.config);
+        let indent = offset.to_string(context.config);
 
         for (i, a) in self.iter().enumerate() {
             let a_str = context.snippet(a.span);