Long string with macro with rustfmt

Hi,

Does rustfmt work with long string literals used with macros (e.g. format!) ? The example shows that it does not, i.e. no effect at all . Is that expected?

fn print_long_string(s: String) -> usize {
    println!("my string: {}", &s);
    s.len()
}

fn main() {
    let length = print_long_string(format!("This is a long string test for Rust, with field 1 {} field 2 {} field 3 {} field 4 {} field 5 {} field 6 {}", 1, 2, 3, 4, 5, 6));
    println!("length: {}", length);
}

Here is the playground link.

Rustfmt seems not reformat the long line in the above code. I found this old issue closed, but not sure what to expect now (Rust 1.50).

I looked at your Playground example. It seemed to work as I would expect. What is the output you were expecting?

I was expecting Rustfmt from "TOOLS" menu would reformat the long line, at least change the format! arguments to a different line.

I don't know that being a macro has anything to do with it.

1 Like

you're right, seems not specific to macros. That said, is this expected behavior from rustfmt?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.