Skip to content

Commit b356fc0

Browse files
authored
Merge pull request #2352 from topecongiro/issue-2337
Break after colon if static item does not fit in a single line
2 parents 09e44b2 + eaab51d commit b356fc0

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
@@ -1567,7 +1567,7 @@ fn rewrite_static(
15671567
context.config.space_before_colon(),
15681568
context.config.space_after_colon(),
15691569
);
1570-
let prefix = format!(
1570+
let mut prefix = format!(
15711571
"{}{}{} {}{}{}",
15721572
format_visibility(static_parts.vis),
15731573
static_parts.defaultness.map_or("", format_defaultness),
@@ -1579,7 +1579,18 @@ fn rewrite_static(
15791579
// 2 = " =".len()
15801580
let ty_shape =
15811581
Shape::indented(offset.block_only(), context.config).offset_left(prefix.len() + 2)?;
1582-
let ty_str = static_parts.ty.rewrite(context, ty_shape)?;
1582+
let ty_str = match static_parts.ty.rewrite(context, ty_shape) {
1583+
Some(ty_str) => ty_str,
1584+
None => {
1585+
if prefix.ends_with(' ') {
1586+
prefix.pop();
1587+
}
1588+
let nested_indent = offset.block_indent(context.config);
1589+
let nested_shape = Shape::indented(nested_indent, context.config);
1590+
let ty_str = static_parts.ty.rewrite(context, nested_shape)?;
1591+
format!("\n{}{}", nested_indent.to_string(context.config), ty_str)
1592+
}
1593+
};
15831594

15841595
if let Some(expr) = static_parts.expr_opt {
15851596
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)