Rustfmt configuration variable for inline macro calls

I have been trying to make rustfmt stop putting macro arguments on separate lines.
I have checked the manual but didn't find anything.

I added a call to rustfmt to my build process in order to force a common coding style.

I'm using a logging library which provides macros for different log levels and I would like to make their calls one-liners in order to stop expanding the code for simple log-calls.

Currently the call:

error!("{} failed to so something {}: {}", &something, &reason.get_exact_reason(), &param.do_something());

will be reformatted to:

error!(
    "{} failed to so something {}: {}",
    &something,
    &reason.get_exact_reason(),
    &param.do_something()
);

which unnecessarily adds many lines of code if I want to make multiple logs in one function.

While I understand that reformatting the code in this way for normal function calls would make sense to improve readability, I don't think its necessary for something like log-calls.

Does anybody know how to do this?

Increasing max_width didn't help and would not necessarily be a good approach anyway, I think.

Unfortunately, I don't think rustfmt knows any difference here. It applies a one-configuration-fits-all perspective, and so if any function-call-like thing is too long, it reformats it.

I should be possible to accept longer function calls, but I don't think there's any precedence for configuring different max widths for particular functions/macros, while still having the shorter max width for everything else.

Increasing max_width a ton should allow this, but it'll allow other super long lines too. And it looks to me like rustfmt currently hardcodes function call width to 60% of max_width, so to set max_width big enough to accept this, you'd need the actual max width to something huge, like 180 or 200.

1 Like

Well that's interesting.
I was hoping for a parameter that either lets me ignore macros from formatting, or lets me increase the number of arguments (or the text length) until the reformatting is done.