Skip to content

Commit eaab51d

Browse files
committed
Break after colon if static item does not fit in a single line
1 parent 631bf68 commit eaab51d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/items.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ fn rewrite_static(
15661566
context.config.space_before_colon(),
15671567
context.config.space_after_colon(),
15681568
);
1569-
let prefix = format!(
1569+
let mut prefix = format!(
15701570
"{}{}{} {}{}{}",
15711571
format_visibility(static_parts.vis),
15721572
static_parts.defaultness.map_or("", format_defaultness),
@@ -1578,7 +1578,18 @@ fn rewrite_static(
15781578
// 2 = " =".len()
15791579
let ty_shape =
15801580
Shape::indented(offset.block_only(), context.config).offset_left(prefix.len() + 2)?;
1581-
let ty_str = static_parts.ty.rewrite(context, ty_shape)?;
1581+
let ty_str = match static_parts.ty.rewrite(context, ty_shape) {
1582+
Some(ty_str) => ty_str,
1583+
None => {
1584+
if prefix.ends_with(' ') {
1585+
prefix.pop();
1586+
}
1587+
let nested_indent = offset.block_indent(context.config);
1588+
let nested_shape = Shape::indented(nested_indent, context.config);
1589+
let ty_str = static_parts.ty.rewrite(context, nested_shape)?;
1590+
format!("\n{}{}", nested_indent.to_string(context.config), ty_str)
1591+
}
1592+
};
15821593

15831594
if let Some(expr) = static_parts.expr_opt {
15841595
let lhs = format!("{}{} =", prefix, ty_str);

tests/source/static.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ impl Color {
1919

2020
// #1391
2121
pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: NTSTATUS = 0 as usize;
22+
23+
pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: Yyyyyyyyyyyyyyyyyyyyyyyyyyyy = 1;

tests/target/static.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ impl Color {
2222
// #1391
2323
pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: NTSTATUS =
2424
0 as usize;
25+
26+
pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:
27+
Yyyyyyyyyyyyyyyyyyyyyyyyyyyy = 1;

0 commit comments

Comments
 (0)