rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Adding inconsistent line breaks around println! calls.

Open DigiTester opened this issue 9 years ago • 2 comments

I've just installed what I hope is the current rustfmt (0.9.0-nightly), and the following code modification seems inconsistent to me:

fn main() {
    println!("size of SerialPacket = {:?}", mem::size_of::<SerialPacket>());
    println!("size of PollPacket   = {:?}", mem::size_of::<PollPacket>());
}

becomes

fn main() {
    println!(
        "size of SerialPacket = {:?}",
        mem::size_of::<SerialPacket>()
    );
    println!("size of PollPacket   = {:?}", mem::size_of::<PollPacket>());
}

after rustfmt with default arguments. Note that the final statement doesn't get split over multiple lines. Worse, adding line breaks to the final line gets "fixed" back to a single line when I re-run rustfmt, so there's no fix other than adding a bunch of suppressions. That inconsistency will make me unhappy.

DigiTester avatar Oct 04 '17 04:10 DigiTester

The difference is whether the char count of arguments exceeds fn_call_width or not. It is set to 60 by default. The first println!'s arguments have 61 chars, whereas the second have 59 chars.

FWIW the latest version is 0.2.8-nightly (the version number is screwed, sorry). You could install it via cargo install rustfmt-nightly --force with the latest nightly toolchain. By using 0.2.8-nightly, rustfmt should be idempotent.

topecongiro avatar Oct 04 '17 10:10 topecongiro

Assuming this is fixed on nightly. Closing (please comment if not and I'll re-open).

nrc avatar Oct 05 '17 11:10 nrc