diff --git a/src/expr.rs b/src/expr.rs index 6928b77f3603..d9fa4717357b 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -92,7 +92,7 @@ pub fn format_expr( rewrite_pair( &**lhs, &**rhs, - PairParts::new("", &format!(" {} ", context.snippet(op.span)), ""), + PairParts::infix(&format!(" {} ", context.snippet(op.span))), context, shape, context.config.binop_separator(), @@ -211,7 +211,7 @@ pub fn format_expr( ast::ExprKind::Cast(ref expr, ref ty) => rewrite_pair( &**expr, &**ty, - PairParts::new("", " as ", ""), + PairParts::infix(" as "), context, shape, SeparatorPlace::Front, @@ -219,7 +219,7 @@ pub fn format_expr( ast::ExprKind::Type(ref expr, ref ty) => rewrite_pair( &**expr, &**ty, - PairParts::new("", ": ", ""), + PairParts::infix(": "), context, shape, SeparatorPlace::Back, @@ -288,7 +288,7 @@ pub fn format_expr( rewrite_pair( &*lhs, &*rhs, - PairParts::new("", &sp_delim, ""), + PairParts::infix(&sp_delim), context, shape, context.config.binop_separator(), @@ -435,6 +435,7 @@ fn rewrite_simple_binaries( None } +/// Sigils that decorate a binop pair. #[derive(new, Clone, Copy)] pub struct PairParts<'a> { prefix: &'a str, @@ -442,6 +443,16 @@ pub struct PairParts<'a> { suffix: &'a str, } +impl<'a> PairParts<'a> { + pub fn infix(infix: &'a str) -> PairParts<'a> { + PairParts { + prefix: "", + infix, + suffix: "", + } + } +} + pub fn rewrite_pair( lhs: &LHS, rhs: &RHS, diff --git a/src/patterns.rs b/src/patterns.rs index 85b9b84b6b2b..5e3cbfc31f3c 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -112,7 +112,7 @@ impl Rewrite for Pat { rewrite_pair( &**lhs, &**rhs, - PairParts::new("", &infix, ""), + PairParts::infix(&infix), context, shape, SeparatorPlace::Front,