Break after colon if static item does not fit in a single line

This commit is contained in:
Seiichi Uchida 2018-01-10 23:23:42 +09:00
parent 631bf68037
commit eaab51db2e
3 changed files with 18 additions and 2 deletions

View file

@ -1566,7 +1566,7 @@ fn rewrite_static(
context.config.space_before_colon(),
context.config.space_after_colon(),
);
let prefix = format!(
let mut prefix = format!(
"{}{}{} {}{}{}",
format_visibility(static_parts.vis),
static_parts.defaultness.map_or("", format_defaultness),
@ -1578,7 +1578,18 @@ fn rewrite_static(
// 2 = " =".len()
let ty_shape =
Shape::indented(offset.block_only(), context.config).offset_left(prefix.len() + 2)?;
let ty_str = static_parts.ty.rewrite(context, ty_shape)?;
let ty_str = match static_parts.ty.rewrite(context, ty_shape) {
Some(ty_str) => ty_str,
None => {
if prefix.ends_with(' ') {
prefix.pop();
}
let nested_indent = offset.block_indent(context.config);
let nested_shape = Shape::indented(nested_indent, context.config);
let ty_str = static_parts.ty.rewrite(context, nested_shape)?;
format!("\n{}{}", nested_indent.to_string(context.config), ty_str)
}
};
if let Some(expr) = static_parts.expr_opt {
let lhs = format!("{}{} =", prefix, ty_str);

View file

@ -19,3 +19,5 @@ impl Color {
// #1391
pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: NTSTATUS = 0 as usize;
pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: Yyyyyyyyyyyyyyyyyyyyyyyyyyyy = 1;

View file

@ -22,3 +22,6 @@ impl Color {
// #1391
pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: NTSTATUS =
0 as usize;
pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:
Yyyyyyyyyyyyyyyyyyyyyyyyyyyy = 1;