Generalize rewrite_assign_rhs()

This commit is contained in:
topecongiro 2017-11-16 11:26:36 +09:00
parent 37b6855d9d
commit 4cd2e6f39a
2 changed files with 7 additions and 7 deletions

View File

@ -2578,10 +2578,10 @@ fn rewrite_assignment(
// The left hand side must contain everything up to, and including, the
// assignment operator.
pub fn rewrite_assign_rhs<S: Into<String>>(
pub fn rewrite_assign_rhs<S: Into<String>, R: Rewrite>(
context: &RewriteContext,
lhs: S,
ex: &ast::Expr,
ex: &R,
shape: Shape,
) -> Option<String> {
let lhs = lhs.into();
@ -2596,9 +2596,9 @@ pub fn rewrite_assign_rhs<S: Into<String>>(
Some(lhs + &rhs)
}
fn choose_rhs(
fn choose_rhs<R: Rewrite>(
context: &RewriteContext,
expr: &ast::Expr,
expr: &R,
shape: Shape,
orig_rhs: Option<String>,
) -> Option<String> {

View File

@ -111,7 +111,7 @@ impl Rewrite for ast::Local {
// 1 = trailing semicolon;
let nested_shape = shape.sub_width(1)?;
result = rewrite_assign_rhs(context, result, ex, nested_shape)?;
result = rewrite_assign_rhs(context, result, &**ex, nested_shape)?;
}
result.push(';');
@ -550,7 +550,7 @@ impl<'a> FmtVisitor<'a> {
ast::VariantData::Unit(..) => if let Some(ref expr) = field.node.disr_expr {
let lhs = format!("{} =", field.node.name);
// 1 = ','
rewrite_assign_rhs(&context, lhs, expr, shape.sub_width(1)?)?
rewrite_assign_rhs(&context, lhs, &**expr, shape.sub_width(1)?)?
} else {
field.node.name.to_string()
},
@ -1593,7 +1593,7 @@ fn rewrite_static(
rewrite_assign_rhs(
context,
lhs,
expr,
&**expr,
Shape::legacy(remaining_width, offset.block_only()),
).and_then(|res| {
recover_comment_removed(res, static_parts.span, context)