-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RustFmt fails to format file with long line within scope of lambda passed to member function #3135
Comments
I hit this today, so here is another example with more info. Notes from my experiments:
fn main() {
rustfmt.will(properly + reformat).this();
foo.bar({
rustfmt .
will(NOT
+
touch
)
.this()
;
{"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
});
} Edit: By "Using |
There is no good formatting here because the string lit is too long for the max width. SO I think in this case, doing nothing and let the user fix it is the right thing to do. |
I would agree about the line in question, but it breaks all the blocks it is in, e.g. in my use case a few hundred lines, and without indication which line is responsible. Also: It also breaks if the long line consists of symbols that are possible to line-break properly (e.g. I had a longer macro invocation in there, not a long string) |
@VeaaC Can you share an example of that long line with a macro ? thanks! |
@Elarnon do you have an example of the following ? I tried to replace the curly brackets around the long string from your comment with a tuple but it didn't get formatted either.
|
@scampi Indeed, I checked again and it does trigger the bug as well. I think I got confused because the behavior around tuples and whitespaces is really weird: fn main() {
foo.bar({
underindented();
{( xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,)}
});
} triggers the bug, but if you do any of the following, it no longer triggers:
BTW I will reiterate that rustfmt works properly with fn main() {
foo::bar({
underindented();
{"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
});
} gets formatted into fn main() {
foo::bar({
underindented();
{
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
});
} which is arguably the "least bad formatting", even if no "good" ones exist. |
This one fails to split a macro (instead of the long string): fn f() {
something.do_stuff
(
|
|
{
error!(context.logger, "metric_production_abcdefgere"; "reason_abcdefg" => format!("{}", e));
}
);
} Making the line any shorter will format the rest of the code normally, but still not split the macro: fn f() {
something.do_stuff(|| {
error!(context.logger, "metric_production_abcdefgere"; "reason_abcde" => format!("{}", e));
});
} |
Is this the same root cause? fn x() {
let near : Vec<u8> = foo("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
} Rustfmt 1.0.0-nightly (2018-11-30 43206f4) reports no errors or warnings, the exit code is zero, and the file is not changed:
|
I faced this issue today, and it tooks me 5 hours to understand the problem was coming from my string which was too long, but rustfmt gave me no warning nor error. |
What's the status of this bug? Will it be fixed? |
Here's another example of something passing through rustfmt despite underindentation. This example may be sufficiently close to the ones above that it is not worth mentioning. But, however, two things are noticeable: 1) Replacing
|
I spent several hours last night trying to figure out why Yes, the static string slice hardcoded into the module was too long to be properly formatted and probably should have been shorter. That is no excuse for why |
I found this unit test in
From
|
I realize this issue has been open longer, but I'm going to close in favor of #3863 because they're duplicative reports but the latter has more focused/actionable discussion. That thread covers the expected/default behavior, existing workarounds and config options, options you'd need to enable to receive warnings/errors, and request for feedback on some new options under consideration. For the non-chain related snippets that were tacked on to this thread:
|
@ted-tanner I appreciate that you're frustrated, but want to note that expressing that frustration across multiple issues doesn't really help move anything forward.
This doesn't sound right. Are you sure you're running You can see rustfmt's behavior in action via this simple playground snippet. If you're still seeing the behavior you described then please open a new issue with a complete MCVE that can be reproduced.
Already covered in #3863 (comment), tl;dr the ability to do so exists but it's turned off by default. |
@calebcartwright I apologize for my poor behavior. It was wrong of me to express my frustration here. Thank you for the gracious manner in which you responded to my not-so-gracious comment. Also, thanks for your hard work on I'm not sure why the rest of the module was not being formatted (it was actually the rest of the file, not the module--my tests in a separate module in the same file also were not being formatted using the command-line, not an editor plugin), but with an adjustment to a long string it is being formatted correctly now. I'll leave my comment on this issue unedited as an example of how not to post comments. |
No worries, we've all been there 😄 |
I tried to reduce it more, but any change caused it to work again.
The text was updated successfully, but these errors were encountered: