Introduce PairParts to reduce the number of args of rewrite_pair()
This commit is contained in:
parent
10cb568c18
commit
c73871c516
3 changed files with 13 additions and 26 deletions
27
src/expr.rs
27
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, RHS>(
|
||||
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(),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue