From cf7e5581369a6a6dc81f0cd507fd0fcc168e240a Mon Sep 17 00:00:00 2001 From: Owen Colley <169960024+penguinawesome1@users.noreply.github.com> Date: Sat, 10 Oct 2026 22:26:59 -0400 Subject: [PATCH 1/4] fix: allow single multiline string lit to overflow after long ident --- src/expr.rs | 6 +++++ tests/source/issue_5029.rs | 49 ++++++++++++++++++++++++++++++++++++++ tests/target/issue_5029.rs | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 tests/source/issue_5029.rs create mode 100644 tests/target/issue_5029.rs diff --git a/src/expr.rs b/src/expr.rs index 48f17fb0fd1..3c14fe554d4 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1593,6 +1593,12 @@ pub(crate) fn can_be_overflowed_expr( | ast::ExprKind::While(..) => { context.config.combine_control_expr() && context.use_block_indent() && args_len == 1 } + ast::ExprKind::Lit(lit) => { + context.config.style_edition() >= StyleEdition::Edition2027 + && args_len == 1 + && lit.kind == LitKind::Str + && lit.symbol.as_str().contains('\n') + } // Handle always block-like expressions ast::ExprKind::Gen(..) diff --git a/tests/source/issue_5029.rs b/tests/source/issue_5029.rs new file mode 100644 index 00000000000..91159386488 --- /dev/null +++ b/tests/source/issue_5029.rs @@ -0,0 +1,49 @@ +// rustfmt-style_edition: 2027 + +pub const MAC: &str = foo!(" + foo + bar +"); + +pub const SHORT_MAC: &str = f!(" + foo + bar +"); + +pub const LONG_MAC: &str = long_foo!(" + foo + bar +"); + +pub const FUN: &str = foo(" + foo + bar +"); + +pub const SHORT_FUN: &str = f(" + foo + bar +"); + +pub const LONG_FUN: &str = long_foo(" + foo + bar +"); + +pub const BAR: &str = bar!(" + foo bar +"); + +pub const BAZ: &str = baz!( + " + foo + bar +" +); + +fn main() { + let bytes1 = hex!(" + 00010203 04050607 + 08090a0b 0c0d0e0f + "); +} diff --git a/tests/target/issue_5029.rs b/tests/target/issue_5029.rs new file mode 100644 index 00000000000..e98ac00e6ab --- /dev/null +++ b/tests/target/issue_5029.rs @@ -0,0 +1,47 @@ +// rustfmt-style_edition: 2027 + +pub const MAC: &str = foo!(" + foo + bar +"); + +pub const SHORT_MAC: &str = f!(" + foo + bar +"); + +pub const LONG_MAC: &str = long_foo!(" + foo + bar +"); + +pub const FUN: &str = foo(" + foo + bar +"); + +pub const SHORT_FUN: &str = f(" + foo + bar +"); + +pub const LONG_FUN: &str = long_foo(" + foo + bar +"); + +pub const BAR: &str = bar!(" + foo bar +"); + +pub const BAZ: &str = baz!(" + foo + bar +"); + +fn main() { + let bytes1 = hex!(" + 00010203 04050607 + 08090a0b 0c0d0e0f + "); +} From 26018dbbff283a5580408c61ba4cff98bf63b504 Mon Sep 17 00:00:00 2001 From: Owen Colley <169960024+penguinawesome1@users.noreply.github.com> Date: Sat, 17 Oct 2026 10:08:54 -0400 Subject: [PATCH 2/4] test: ensure call with multiline string wraps on max width and fn call width --- tests/source/issue_5029.rs | 21 +++++++++++++++++++++ tests/target/issue_5029.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/tests/source/issue_5029.rs b/tests/source/issue_5029.rs index 91159386488..5819b0f4923 100644 --- a/tests/source/issue_5029.rs +++ b/tests/source/issue_5029.rs @@ -47,3 +47,24 @@ fn main() { 08090a0b 0c0d0e0f "); } + +// Default settings: `fn_call_width` is 60. `max_width` is 100. +// First line string length is 59. Line length is 98. +pub const ABCDEFGHIJKLMN: &str = foo!("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 + next_line +"); + +// First line string length is 60. Line length is 98. +pub const ABCDEFGHIJKLM: &str = foo!("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567 + next_line +"); + +// First line string length is 59. Line length is 99. +pub const ABCDEFGHIJKLMNO: &str = foo!("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 + next_line +"); + +// First line string length is 60. Line length is 99. +pub const ABCDEFGHIJKLMN: &str = foo!("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567 + next_line +"); diff --git a/tests/target/issue_5029.rs b/tests/target/issue_5029.rs index e98ac00e6ab..ea795634cc7 100644 --- a/tests/target/issue_5029.rs +++ b/tests/target/issue_5029.rs @@ -45,3 +45,29 @@ fn main() { 08090a0b 0c0d0e0f "); } + +// Default settings: `fn_call_width` is 60. `max_width` is 100. +// First line string length is 59. Line length is 98. +pub const ABCDEFGHIJKLMN: &str = foo!("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 + next_line +"); + +// First line string length is 60. Line length is 98. +pub const ABCDEFGHIJKLM: &str = foo!( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567 + next_line +" +); + +// First line string length is 59. Line length is 99. +pub const ABCDEFGHIJKLMNO: &str = + foo!("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 + next_line +"); + +// First line string length is 60. Line length is 99. +pub const ABCDEFGHIJKLMN: &str = foo!( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567 + next_line +" +); From 0f2d98fb9f3d92a6bed9c6f13be17c13b851465a Mon Sep 17 00:00:00 2001 From: Owen Colley <169960024+penguinawesome1@users.noreply.github.com> Date: Sat, 17 Oct 2026 10:33:29 -0400 Subject: [PATCH 3/4] chore: update issue_5029 test directives to new //@ syntax --- tests/source/issue_5029.rs | 2 +- tests/target/issue_5029.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/source/issue_5029.rs b/tests/source/issue_5029.rs index 5819b0f4923..a81852f8ebd 100644 --- a/tests/source/issue_5029.rs +++ b/tests/source/issue_5029.rs @@ -1,4 +1,4 @@ -// rustfmt-style_edition: 2027 +//@ rustfmt-style_edition: 2027 pub const MAC: &str = foo!(" foo diff --git a/tests/target/issue_5029.rs b/tests/target/issue_5029.rs index ea795634cc7..de2a130acd2 100644 --- a/tests/target/issue_5029.rs +++ b/tests/target/issue_5029.rs @@ -1,4 +1,4 @@ -// rustfmt-style_edition: 2027 +//@ rustfmt-style_edition: 2027 pub const MAC: &str = foo!(" foo From c202318a2ab364a5192898d5af649af8e2c21174 Mon Sep 17 00:00:00 2001 From: Owen Colley <169960024+penguinawesome1@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:35:39 -0400 Subject: [PATCH 4/4] test: add multiline string cases for function calls --- tests/source/issue_5029.rs | 25 +++++++++++++++++++++++++ tests/target/issue_5029.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/tests/source/issue_5029.rs b/tests/source/issue_5029.rs index a81852f8ebd..966c67d86d4 100644 --- a/tests/source/issue_5029.rs +++ b/tests/source/issue_5029.rs @@ -49,6 +49,31 @@ fn main() { } // Default settings: `fn_call_width` is 60. `max_width` is 100. + +// functions: + +// First line string length is 59. Line length is 98. +pub const ABCDEFGHIJKLMNO: &str = foo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 + next_line +"); + +// First line string length is 60. Line length is 98. +pub const ABCDEFGHIJKLMN: &str = foo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567 + next_line +"); + +// First line string length is 59. Line length is 99. +pub const ABCDEFGHIJKLMNOP: &str = foo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 + next_line +"); + +// First line string length is 60. Line length is 99. +pub const ABCDEFGHIJKLMNO: &str = foo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567 + next_line +"); + +// function macros: + // First line string length is 59. Line length is 98. pub const ABCDEFGHIJKLMN: &str = foo!("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 next_line diff --git a/tests/target/issue_5029.rs b/tests/target/issue_5029.rs index de2a130acd2..35924570971 100644 --- a/tests/target/issue_5029.rs +++ b/tests/target/issue_5029.rs @@ -47,6 +47,36 @@ fn main() { } // Default settings: `fn_call_width` is 60. `max_width` is 100. + +// functions: + +// First line string length is 59. Line length is 98. +pub const ABCDEFGHIJKLMNO: &str = foo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 + next_line +"); + +// First line string length is 60. Line length is 98. +pub const ABCDEFGHIJKLMN: &str = foo( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567 + next_line +", +); + +// First line string length is 59. Line length is 99. +pub const ABCDEFGHIJKLMNOP: &str = + foo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 + next_line +"); + +// First line string length is 60. Line length is 99. +pub const ABCDEFGHIJKLMNO: &str = foo( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567 + next_line +", +); + +// function macros: + // First line string length is 59. Line length is 98. pub const ABCDEFGHIJKLMN: &str = foo!("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 next_line