rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.05k stars 888 forks source link

Method calls with a long literal string doesn't get formatted #6365

Closed musjj closed 1 month ago

musjj commented 1 month ago

Some method calls won't format if there's a long literal string in it. For example, an .expect() with a long message:

fn foo() {
    let _: i32 = "42".parse::<i32>() 
    .expect("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}

rustfmt will skip formatting in this entire line. You can test it in in the playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=135ec08b2266e6e642bb1603f7592100. If you shorten the string by a single char, it will get formatted correctly.

Tested with rustfmt 1.8.0-nightly (eb4e234674 2024-10-09).

ytmimi commented 1 month ago

Duplicate of https://github.com/rust-lang/rustfmt/issues/3863