@@ -15,8 +15,7 @@ use Indent;
15
15
use rewrite:: { Rewrite , RewriteContext } ;
16
16
use lists:: { write_list, itemize_list, ListFormatting , SeparatorTactic , ListTactic } ;
17
17
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} ;
20
19
use visitor:: FmtVisitor ;
21
20
use config:: { StructLitStyle , MultilineStyle } ;
22
21
use comment:: { FindUncommented , rewrite_comment, contains_comment} ;
@@ -268,7 +267,7 @@ fn rewrite_closure(capture: ast::CaptureClause,
268
267
if !ret_str. is_empty ( ) {
269
268
if prefix. contains ( '\n' ) {
270
269
prefix. push ( '\n' ) ;
271
- prefix. push_str ( & make_indent ( argument_offset, context. config ) ) ;
270
+ prefix. push_str ( & argument_offset. to_string ( context. config ) ) ;
272
271
} else {
273
272
prefix. push ( ' ' ) ;
274
273
}
@@ -311,12 +310,12 @@ fn rewrite_closure(capture: ast::CaptureClause,
311
310
. as_ref ( )
312
311
. and_then ( |body_expr| {
313
312
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 ( ) ) )
315
314
} else {
316
315
None
317
316
}
318
317
} )
319
- . unwrap_or_else ( || body. rewrite ( & context, 2 , Indent :: new ( 0 , 0 ) ) ) ;
318
+ . unwrap_or_else ( || body. rewrite ( & context, 2 , Indent :: empty ( ) ) ) ;
320
319
321
320
Some ( format ! ( "{} {}" , prefix, try_opt!( body_rewrite) ) )
322
321
}
@@ -592,11 +591,11 @@ fn single_line_if_else(context: &RewriteContext,
592
591
593
592
let new_width = try_opt ! ( width. checked_sub( pat_expr_str. len( ) + fixed_cost) ) ;
594
593
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 ( ) ) ) ;
596
595
597
596
let new_width = try_opt ! ( new_width. checked_sub( if_str. len( ) ) ) ;
598
597
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 ( ) ) ) ;
600
599
601
600
// FIXME: this check shouldn't be necessary. Rewrites should either fail
602
601
// or wrap to a newline when the object does not fit the width.
@@ -638,7 +637,7 @@ fn rewrite_match(context: &RewriteContext,
638
637
639
638
let nested_context = context. nested_context ( ) ;
640
639
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 ) ;
642
641
643
642
let open_brace_pos = span_after ( mk_sp ( cond. span . hi , arm_start_pos ( & arms[ 0 ] ) ) ,
644
643
"{" ,
@@ -688,7 +687,7 @@ fn rewrite_match(context: &RewriteContext,
688
687
// match expression, but meh.
689
688
690
689
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 ) ) ;
692
691
result. push ( '}' ) ;
693
692
Some ( result)
694
693
}
@@ -710,7 +709,7 @@ fn arm_end_pos(arm: &ast::Arm) -> BytePos {
710
709
impl Rewrite for ast:: Arm {
711
710
fn rewrite ( & self , context : & RewriteContext , width : usize , offset : Indent ) -> Option < String > {
712
711
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 ) ;
714
713
715
714
// FIXME this is all a bit grotty, would be nice to abstract out the
716
715
// treatment of attributes.
@@ -738,7 +737,7 @@ impl Rewrite for ast::Arm {
738
737
. map( |p| {
739
738
p. rewrite( context,
740
739
pat_budget,
741
- offset. block_indent( context. config. tab_spaces ) )
740
+ offset. block_indent( context. config) )
742
741
} )
743
742
. collect:: <Option <Vec <_>>>( ) ) ;
744
743
@@ -784,7 +783,7 @@ impl Rewrite for ast::Arm {
784
783
785
784
let mut line_indent = offset + pats_width;
786
785
if vertical {
787
- line_indent = line_indent. block_indent ( context. config . tab_spaces ) ;
786
+ line_indent = line_indent. block_indent ( context. config ) ;
788
787
}
789
788
790
789
let comma = if let ast:: ExprBlock ( _) = body. node {
@@ -819,7 +818,7 @@ impl Rewrite for ast::Arm {
819
818
Some ( format ! ( "{}{} =>\n {}{}," ,
820
819
attr_str. trim_left( ) ,
821
820
pats_str,
822
- make_indent ( offset. block_indent( context. config. tab_spaces ) , context. config) ,
821
+ offset. block_indent( context. config) . to_string ( context. config) ,
823
822
body_str) )
824
823
}
825
824
}
@@ -849,11 +848,10 @@ fn rewrite_guard(context: &RewriteContext,
849
848
if overhead < width {
850
849
let cond_str = guard. rewrite ( context,
851
850
width - overhead,
852
- offset. block_indent ( context. config . tab_spaces ) ) ;
851
+ offset. block_indent ( context. config ) ) ;
853
852
if let Some ( cond_str) = cond_str {
854
853
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) ,
857
855
cond_str) ) ;
858
856
}
859
857
}
@@ -908,7 +906,7 @@ fn rewrite_pat_expr(context: &RewriteContext,
908
906
909
907
// The expression won't fit on the current line, jump to next.
910
908
result. push ( '\n' ) ;
911
- result. push_str ( & make_indent ( pat_offset, context. config ) ) ;
909
+ result. push_str ( & pat_offset. to_string ( context. config ) ) ;
912
910
913
911
let expr_rewrite = expr. rewrite ( context,
914
912
context. config . max_width - pat_offset. width ( ) ,
@@ -1067,7 +1065,7 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
1067
1065
StructLitStyle :: Block => {
1068
1066
// If we are all on one line, then we'll ignore the indent, and we
1069
1067
// 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 ) ;
1071
1069
let v_budget = context. config . max_width . checked_sub ( indent. width ( ) ) . unwrap_or ( 0 ) ;
1072
1070
( indent, v_budget)
1073
1071
}
@@ -1139,10 +1137,10 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
1139
1137
let fields_str = try_opt ! ( write_list( & items. collect:: <Vec <_>>( ) , & fmt) ) ;
1140
1138
1141
1139
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 ) ;
1146
1144
Some ( format ! ( "{} {{\n {}{}\n {}}}" , path_str, inner_indent, fields_str, outer_indent) )
1147
1145
} ;
1148
1146
@@ -1255,7 +1253,7 @@ fn rewrite_binary_op(context: &RewriteContext,
1255
1253
Some ( format ! ( "{} {}\n {}{}" ,
1256
1254
try_opt!( lhs. rewrite( context, budget, offset) ) ,
1257
1255
operator_str,
1258
- make_indent ( offset, context. config) ,
1256
+ offset. to_string ( context. config) ,
1259
1257
rhs_result) )
1260
1258
}
1261
1259
@@ -1319,8 +1317,8 @@ pub fn rewrite_assign_rhs<S: Into<String>>(context: &RewriteContext,
1319
1317
None => {
1320
1318
// Expression did not fit on the same line as the identifier. Retry
1321
1319
// 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) ) ) ;
1324
1322
1325
1323
// FIXME: we probably should related max_width to width instead of config.max_width
1326
1324
// where is the 1 coming from anyway?
0 commit comments