Merge pull request #2352 from topecongiro/issue-2337

Break after colon if static item does not fit in a single line
This commit is contained in:
Nick Cameron 2018-01-12 17:31:12 +13:00 committed by GitHub
commit b356fc06f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -1567,7 +1567,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),
@ -1579,7 +1579,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;