diff --git a/src/expr.rs b/src/expr.rs index d815bbe8dd7f..0fc2743e57eb 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -83,9 +83,7 @@ pub fn format_expr( rewrite_pair( &**lhs, &**rhs, - "", - &format!(" {} ", context.snippet(op.span)), - "", + &PairParts("", &format!(" {} ", context.snippet(op.span)), ""), context, shape, context.config.binop_separator(), @@ -186,9 +184,7 @@ pub fn format_expr( ast::ExprKind::Cast(ref expr, ref ty) => rewrite_pair( &**expr, &**ty, - "", - " as ", - "", + &PairParts("", " as ", ""), context, shape, SeparatorPlace::Front, @@ -196,9 +192,7 @@ pub fn format_expr( ast::ExprKind::Type(ref expr, ref ty) => rewrite_pair( &**expr, &**ty, - "", - ": ", - "", + &PairParts("", ": ", ""), context, shape, SeparatorPlace::Back, @@ -215,9 +209,7 @@ pub fn format_expr( rewrite_pair( &**expr, &**repeats, - lbr, - "; ", - rbr, + &PairParts(lbr, "; ", rbr), context, shape, SeparatorPlace::Back, @@ -253,9 +245,7 @@ pub fn format_expr( rewrite_pair( &*lhs, &*rhs, - "", - &sp_delim, - "", + &PairParts("", &sp_delim, ""), context, shape, SeparatorPlace::Front, @@ -315,12 +305,12 @@ pub fn format_expr( }) } +pub struct PairParts<'a>(pub &'a str, pub &'a str, pub &'a str); + pub fn rewrite_pair( lhs: &LHS, rhs: &RHS, - prefix: &str, - infix: &str, - suffix: &str, + pp: &PairParts, context: &RewriteContext, shape: Shape, separator_place: SeparatorPlace, @@ -329,6 +319,7 @@ where LHS: Rewrite, RHS: Rewrite, { + let &PairParts(prefix, infix, suffix) = pp; let lhs_overhead = match separator_place { SeparatorPlace::Back => shape.used_width() + prefix.len() + infix.trim_right().len(), SeparatorPlace::Front => shape.used_width(), diff --git a/src/patterns.rs b/src/patterns.rs index 92e385543b7a..38d850962bbb 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -16,7 +16,7 @@ use spanned::Spanned; use codemap::SpanUtils; use comment::FindUncommented; use expr::{can_be_overflowed_expr, rewrite_call_inner, rewrite_pair, rewrite_unary_prefix, - wrap_struct_field}; + wrap_struct_field, PairParts}; use lists::{itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape, struct_lit_tactic, write_list, DefinitiveListTactic, SeparatorPlace, SeparatorTactic}; use rewrite::{Rewrite, RewriteContext}; @@ -65,9 +65,7 @@ impl Rewrite for Pat { rewrite_pair( &**lhs, &**rhs, - "", - infix, - "", + &PairParts("", infix, ""), context, shape, SeparatorPlace::Front, diff --git a/src/types.rs b/src/types.rs index a0b3a7c196a0..26b5f702a70f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -19,7 +19,7 @@ use syntax::symbol::keywords; use spanned::Spanned; use codemap::SpanUtils; use config::{IndentStyle, Style, TypeDensity}; -use expr::{rewrite_pair, rewrite_tuple, rewrite_unary_prefix, wrap_args_with_parens}; +use expr::{rewrite_pair, rewrite_tuple, rewrite_unary_prefix, wrap_args_with_parens, PairParts}; use items::{format_generics_item_list, generics_shape_from_config}; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListTactic, Separator, SeparatorPlace, SeparatorTactic}; @@ -709,9 +709,7 @@ impl Rewrite for ast::Ty { rewrite_pair( &**ty, &**repeats, - lbr, - "; ", - rbr, + &PairParts(lbr, "; ", rbr), context, shape, SeparatorPlace::Back,