Description
The following example does not get formatted at all when running cargo fmt
, and does not report anything on cargo fmt --check
. I've set max_width = 50
to make it easier to visualize, but similar behavior can be seen with the default max width.
// max width of 50 characters is here ---------->|
fn _finagle() {
let _my_string =
"The quick brown fox jumps over the lazy dog."
.split(" ")
.next()
.unwrap();
}
This seems to be triggered by the fact that the string literal cannot be formatted to fit within max_width
, which can be demonstrated by shortening it. Removing "lazy" causes the above example to get formatted to this:
// max width of 50 characters is here ---------->|
fn _finagle() {
let _my_string =
"The quick brown fox jumps over the dog."
.split(" ")
.next()
.unwrap();
}
However, I would have expected the original example to format to this:
// max width of 50 characters is here ---------->|
fn _finagle() {
let _my_string =
"The quick brown fox jumps over the lazy dog."
.split(" ")
.next()
.unwrap();
}
It seems strange for the formatter to give up on the entire statement and ignore random blank lines and indentation if part of it can't be fit within the line length limit.
I'm using rustfmt 1.8.0-stable (05f9846f89 2025-03-31)
with edition = "2024"
.