Use rewrite_assign_rhs() when rewriting associated type

This commit is contained in:
topecongiro 2017-11-16 11:27:11 +09:00
parent 4cd2e6f39a
commit f7ef1f681c

View file

@ -1613,10 +1613,9 @@ pub fn rewrite_associated_type(
) -> Option<String> {
let prefix = format!("type {}", ident);
let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt {
let type_bounds_str = if let Some(ref bounds) = ty_param_bounds_opt {
// 2 = ": ".len()
let shape = Shape::indented(indent, context.config).offset_left(prefix.len() + 2)?;
let bounds: &[_] = ty_param_bounds;
let bound_str = bounds
.iter()
.map(|ty_bound| ty_bound.rewrite(context, shape))
@ -1631,14 +1630,10 @@ pub fn rewrite_associated_type(
};
if let Some(ty) = ty_opt {
let ty_str = ty.rewrite(
context,
Shape::legacy(
context.budget(indent.block_indent + prefix.len() + 2),
indent.block_only(),
),
)?;
Some(format!("{}{} = {};", prefix, type_bounds_str, ty_str))
// 1 = `;`
let shape = Shape::indented(indent, context.config).sub_width(1)?;
let lhs = format!("{}{} =", prefix, type_bounds_str);
rewrite_assign_rhs(context, lhs, &**ty, shape).map(|s| s + ";")
} else {
Some(format!("{}{};", prefix, type_bounds_str))
}