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