From eaab51db2eafae35d8e631ecd5ed90673c783336 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Wed, 10 Jan 2018 23:23:42 +0900 Subject: [PATCH] Break after colon if static item does not fit in a single line --- src/items.rs | 15 +++++++++++++-- tests/source/static.rs | 2 ++ tests/target/static.rs | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/items.rs b/src/items.rs index d8d490f72c0..183373c7347 100644 --- a/src/items.rs +++ b/src/items.rs @@ -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); diff --git a/tests/source/static.rs b/tests/source/static.rs index b51c56d1205..970786381cc 100644 --- a/tests/source/static.rs +++ b/tests/source/static.rs @@ -19,3 +19,5 @@ impl Color { // #1391 pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: NTSTATUS = 0 as usize; + +pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: Yyyyyyyyyyyyyyyyyyyyyyyyyyyy = 1; diff --git a/tests/target/static.rs b/tests/target/static.rs index dc1a5c78c5d..5daccf3e7f7 100644 --- a/tests/target/static.rs +++ b/tests/target/static.rs @@ -22,3 +22,6 @@ impl Color { // #1391 pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: NTSTATUS = 0 as usize; + +pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: + Yyyyyyyyyyyyyyyyyyyyyyyyyyyy = 1;