Skip to content

Commit f51ee1c

Browse files
SiegeLordExSiegeLord
authored andcommitted
Add Indent::none(), remove make_indent.
1 parent df2fb66 commit f51ee1c

File tree

11 files changed

+82
-92
lines changed

11 files changed

+82
-92
lines changed

src/chains.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
use Indent;
2323
use rewrite::{Rewrite, RewriteContext};
24-
use utils::{first_line_width, make_indent};
24+
use utils::first_line_width;
2525
use expr::rewrite_call;
2626

2727
use syntax::{ast, ptr};
@@ -117,7 +117,7 @@ pub fn rewrite_chain(mut expr: &ast::Expr,
117117
let connector = if fits_single_line {
118118
String::new()
119119
} else {
120-
format!("\n{}", make_indent(indent, context.config))
120+
format!("\n{}", indent.to_string(context.config))
121121
};
122122

123123
let first_connector = if extend {

src/comment.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::iter;
1515
use Indent;
1616
use config::Config;
1717
use string::{StringFormat, rewrite_string};
18-
use utils::make_indent;
1918

2019
pub fn rewrite_comment(orig: &str,
2120
block_style: bool,
@@ -45,7 +44,7 @@ pub fn rewrite_comment(orig: &str,
4544
config: config,
4645
};
4746

48-
let indent_str = make_indent(offset, config);
47+
let indent_str = offset.to_string(config);
4948
let line_breaks = s.chars().filter(|&c| c == '\n').count();
5049

5150
let (_, mut s) = s.lines()
@@ -304,7 +303,7 @@ mod test {
304303
assert_eq!("/* test */", rewrite_comment(" //test", true, 100, Indent::new(0, 100),
305304
&config));
306305
assert_eq!("// comment\n// on a", rewrite_comment("// comment on a", false, 10,
307-
Indent::new(0, 0), &config));
306+
Indent::empty(), &config));
308307

309308
assert_eq!("// A multi line comment\n // between args.",
310309
rewrite_comment("// A multi line comment\n // between args.",

src/expr.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use Indent;
1515
use rewrite::{Rewrite, RewriteContext};
1616
use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTactic};
1717
use string::{StringFormat, rewrite_string};
18-
use utils::{span_after, make_indent, extra_offset, first_line_width, last_line_width, wrap_str,
19-
binary_search};
18+
use utils::{span_after, extra_offset, first_line_width, last_line_width, wrap_str, binary_search};
2019
use visitor::FmtVisitor;
2120
use config::{StructLitStyle, MultilineStyle};
2221
use comment::{FindUncommented, rewrite_comment, contains_comment};
@@ -268,7 +267,7 @@ fn rewrite_closure(capture: ast::CaptureClause,
268267
if !ret_str.is_empty() {
269268
if prefix.contains('\n') {
270269
prefix.push('\n');
271-
prefix.push_str(&make_indent(argument_offset, context.config));
270+
prefix.push_str(&argument_offset.to_string(context.config));
272271
} else {
273272
prefix.push(' ');
274273
}
@@ -311,12 +310,12 @@ fn rewrite_closure(capture: ast::CaptureClause,
311310
.as_ref()
312311
.and_then(|body_expr| {
313312
if let ast::Expr_::ExprBlock(ref inner) = body_expr.node {
314-
Some(inner.rewrite(&context, 2, Indent::new(0, 0)))
313+
Some(inner.rewrite(&context, 2, Indent::empty()))
315314
} else {
316315
None
317316
}
318317
})
319-
.unwrap_or_else(|| body.rewrite(&context, 2, Indent::new(0, 0)));
318+
.unwrap_or_else(|| body.rewrite(&context, 2, Indent::empty()));
320319

321320
Some(format!("{} {}", prefix, try_opt!(body_rewrite)))
322321
}
@@ -592,11 +591,11 @@ fn single_line_if_else(context: &RewriteContext,
592591

593592
let new_width = try_opt!(width.checked_sub(pat_expr_str.len() + fixed_cost));
594593
let if_expr = if_node.expr.as_ref().unwrap();
595-
let if_str = try_opt!(if_expr.rewrite(context, new_width, Indent::new(0, 0)));
594+
let if_str = try_opt!(if_expr.rewrite(context, new_width, Indent::empty()));
596595

597596
let new_width = try_opt!(new_width.checked_sub(if_str.len()));
598597
let else_expr = else_node.expr.as_ref().unwrap();
599-
let else_str = try_opt!(else_expr.rewrite(context, new_width, Indent::new(0, 0)));
598+
let else_str = try_opt!(else_expr.rewrite(context, new_width, Indent::empty()));
600599

601600
// FIXME: this check shouldn't be necessary. Rewrites should either fail
602601
// or wrap to a newline when the object does not fit the width.
@@ -638,7 +637,7 @@ fn rewrite_match(context: &RewriteContext,
638637

639638
let nested_context = context.nested_context();
640639
let arm_indent = nested_context.block_indent + context.overflow_indent;
641-
let arm_indent_str = make_indent(arm_indent, context.config);
640+
let arm_indent_str = arm_indent.to_string(context.config);
642641

643642
let open_brace_pos = span_after(mk_sp(cond.span.hi, arm_start_pos(&arms[0])),
644643
"{",
@@ -688,7 +687,7 @@ fn rewrite_match(context: &RewriteContext,
688687
// match expression, but meh.
689688

690689
result.push('\n');
691-
result.push_str(&make_indent(context.block_indent + context.overflow_indent, context.config));
690+
result.push_str(&(context.block_indent + context.overflow_indent).to_string(context.config));
692691
result.push('}');
693692
Some(result)
694693
}
@@ -710,7 +709,7 @@ fn arm_end_pos(arm: &ast::Arm) -> BytePos {
710709
impl Rewrite for ast::Arm {
711710
fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
712711
let &ast::Arm { ref attrs, ref pats, ref guard, ref body } = self;
713-
let indent_str = make_indent(offset, context.config);
712+
let indent_str = offset.to_string(context.config);
714713

715714
// FIXME this is all a bit grotty, would be nice to abstract out the
716715
// treatment of attributes.
@@ -738,7 +737,7 @@ impl Rewrite for ast::Arm {
738737
.map(|p| {
739738
p.rewrite(context,
740739
pat_budget,
741-
offset.block_indent(context.config.tab_spaces))
740+
offset.block_indent(context.config))
742741
})
743742
.collect::<Option<Vec<_>>>());
744743

@@ -784,7 +783,7 @@ impl Rewrite for ast::Arm {
784783

785784
let mut line_indent = offset + pats_width;
786785
if vertical {
787-
line_indent = line_indent.block_indent(context.config.tab_spaces);
786+
line_indent = line_indent.block_indent(context.config);
788787
}
789788

790789
let comma = if let ast::ExprBlock(_) = body.node {
@@ -819,7 +818,7 @@ impl Rewrite for ast::Arm {
819818
Some(format!("{}{} =>\n{}{},",
820819
attr_str.trim_left(),
821820
pats_str,
822-
make_indent(offset.block_indent(context.config.tab_spaces), context.config),
821+
offset.block_indent(context.config).to_string(context.config),
823822
body_str))
824823
}
825824
}
@@ -849,11 +848,10 @@ fn rewrite_guard(context: &RewriteContext,
849848
if overhead < width {
850849
let cond_str = guard.rewrite(context,
851850
width - overhead,
852-
offset.block_indent(context.config.tab_spaces));
851+
offset.block_indent(context.config));
853852
if let Some(cond_str) = cond_str {
854853
return Some(format!("\n{}if {}",
855-
make_indent(offset.block_indent(context.config.tab_spaces),
856-
context.config),
854+
offset.block_indent(context.config).to_string(context.config),
857855
cond_str));
858856
}
859857
}
@@ -908,7 +906,7 @@ fn rewrite_pat_expr(context: &RewriteContext,
908906

909907
// The expression won't fit on the current line, jump to next.
910908
result.push('\n');
911-
result.push_str(&make_indent(pat_offset, context.config));
909+
result.push_str(&pat_offset.to_string(context.config));
912910

913911
let expr_rewrite = expr.rewrite(context,
914912
context.config.max_width - pat_offset.width(),
@@ -1067,7 +1065,7 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
10671065
StructLitStyle::Block => {
10681066
// If we are all on one line, then we'll ignore the indent, and we
10691067
// have a smaller budget.
1070-
let indent = context.block_indent.block_indent(context.config.tab_spaces);
1068+
let indent = context.block_indent.block_indent(context.config);
10711069
let v_budget = context.config.max_width.checked_sub(indent.width()).unwrap_or(0);
10721070
(indent, v_budget)
10731071
}
@@ -1139,10 +1137,10 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
11391137
let fields_str = try_opt!(write_list(&items.collect::<Vec<_>>(), &fmt));
11401138

11411139
let format_on_newline = || {
1142-
let inner_indent = make_indent(context.block_indent
1143-
.block_indent(context.config.tab_spaces),
1144-
context.config);
1145-
let outer_indent = make_indent(context.block_indent, context.config);
1140+
let inner_indent = context.block_indent
1141+
.block_indent(context.config)
1142+
.to_string(context.config);
1143+
let outer_indent = context.block_indent.to_string(context.config);
11461144
Some(format!("{} {{\n{}{}\n{}}}", path_str, inner_indent, fields_str, outer_indent))
11471145
};
11481146

@@ -1255,7 +1253,7 @@ fn rewrite_binary_op(context: &RewriteContext,
12551253
Some(format!("{} {}\n{}{}",
12561254
try_opt!(lhs.rewrite(context, budget, offset)),
12571255
operator_str,
1258-
make_indent(offset, context.config),
1256+
offset.to_string(context.config),
12591257
rhs_result))
12601258
}
12611259

@@ -1319,8 +1317,8 @@ pub fn rewrite_assign_rhs<S: Into<String>>(context: &RewriteContext,
13191317
None => {
13201318
// Expression did not fit on the same line as the identifier. Retry
13211319
// on the next line.
1322-
let new_offset = offset.block_indent(context.config.tab_spaces);
1323-
result.push_str(&format!("\n{}", make_indent(new_offset, context.config)));
1320+
let new_offset = offset.block_indent(context.config);
1321+
result.push_str(&format!("\n{}", new_offset.to_string(context.config)));
13241322

13251323
// FIXME: we probably should related max_width to width instead of config.max_width
13261324
// where is the 1 coming from anyway?

0 commit comments

Comments
 (0)