Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,19 @@ impl Rewrite for Chain {
formatter.format_last_child(context, shape, child_shape)?;

let result = formatter.join_rewrites(context, child_shape)?;
wrap_str(result, context.config.max_width(), shape).max_width_error(shape.width, full_span)
let max_width = if context.config.style_edition() >= StyleEdition::Edition2027 {
// Keep formatting the chain when a nested expression contains an unavoidable,
// pre-existing overflow, but do not allow the rewrite to make it any wider.
crate::comment::filter_normal_code(context.snippet(full_span))
.lines()
.map(utils::unicode_str_width)
.max()
.unwrap_or(0)
.max(context.config.max_width())
} else {
context.config.max_width()
};
wrap_str(result, max_width, shape).max_width_error(shape.width, full_span)
}
}

Expand Down
11 changes: 11 additions & 0 deletions tests/source/issue_6977_style_edition_2024.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// rustfmt-style_edition: 2024

fn main() {
some_struct.foo(format!(
"{}", if true {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
} else {
""
},
));
}
11 changes: 11 additions & 0 deletions tests/source/issue_6977_style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// rustfmt-style_edition: 2027

fn main() {
some_struct.foo(format!(
"{}", if true {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
} else {
""
},
));
}
11 changes: 11 additions & 0 deletions tests/target/issue_6977_style_edition_2024.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// rustfmt-style_edition: 2024

fn main() {
some_struct.foo(format!(
"{}", if true {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
} else {
""
},
));
}
12 changes: 12 additions & 0 deletions tests/target/issue_6977_style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// rustfmt-style_edition: 2027

fn main() {
some_struct.foo(format!(
"{}",
if true {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
} else {
""
},
));
}