-
Notifications
You must be signed in to change notification settings - Fork 898
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 with errors "left behind trailing whitespace" #2896
Comments
rustfmt is failing due to this line. |
|
Thank you! |
Hi. I think this bug still exists.
|
Thanks! Looks like there was another issue when there is comment between closure's argument list and its body. E.g. |foo|
// comment
foo + 3; |
You're welcome. Before rustfmt 1.0, is there any plan to run https://github.com/rust-lang-nursery/crater but for rustfmt? That would actually highlight any bugs like this and also ones that result in compilation/test failures. |
With the file below, the error is a bit different, but also more informative: fn main() {
let toto = |foo|
// my comment
foo + 3;
} The error:
Tested with |
Does not look related, but rustfmt is also failing to format the long lines https://github.com/frankmcsherry/differential-dataflow/blob/master/src/trace/implementations/ord.rs#L210 and https://github.com/frankmcsherry/differential-dataflow/blob/master/src/trace/implementations/ord.rs#L301. The rest of the file seems to have been correctly formatted. Should I open a new bug report? |
Are bugs like this not going to be fixed before the 1.0.0 release? |
It will not - what's on beta is what will be in the 1.0. We can fix this post-1.0, since the warning can be fixed without being backwards incompatible |
Could be a separate issue, but rustfmt fails with the following code.
error:
Tested with |
I also got 5 of these errors today after |
Pull request #4391 should resolve the issue. Seem to be because when a comment at the end of a line is moved to a new line, there is no trimming of the blanks before the comment. The PR splits the result line, strip whitespaces from the end of each line and recombine the lines. |
fyi, here is another example where I am hitting this issue Error:
With the error occurring on the long Strings. (manually wrapping the strings fixes the issue) Here is the complete code:
|
@mikechambers, the error happens because line 11 is not empty but starts with whitespaces. rustfmt does not trim lines that includes only whitespaces (I don't know if this is by design). The error doesn't seem to be related to the long strings. |
@davidBar-On While digging a bit into #4663, I found that doesn't seem to be true. For example: That code has trailing whitespace on line 2. If you reformat the code, |
@davepacheco, I retried to format both the code in this issue and the code in #4663, and found that when using It seems that the whitespace error was fixed during last few months (as far as I remember, when I wrote the note on Nov., the error still occured). |
Perhaps I can provide some clarity here... rustfmt is an AST-driven pretty printer type of code formatter which means that it visits and has to emit something for each node in the tree. In cases where rustfmt fails to format a particular node in the AST (which can happen for myriad reasons), the raw contents within the span of that node are emitted back out (i.e. the original snippet exactly as it was in the original input). This is done to prevent deleting parts of your code just because rustfmt failed to format those parts. If the original input contained trailing whitespace in one of these failed-to-format cases, then accordingly the output/emitted formatting will too, and that in turn later triggers the Additionally, though that |
I am still getting this error on |
I am still getting this error on |
It seems that the issue was fixed in version Two. With |
@davidBar-On and @pozm, would you mind sharing the code snippets that you're using to test / trigger the issue respectively. I want to make sure we're all on the same page here. As mentioned in #2896 (comment) there are potentially many different reasons for rustfmt to inform you that it "left behind trailing whitespace", so you each might be running into a different underlying issue. |
@ytmimi, I used the code from @mikechambers comment above. |
Unfortunately I believe this issue has outlived its utility, and has become a pile on that's sprawled in too many directions to be an efficient means of addressing anything. The original report, and thus sole scope, of this issue was utilizing a different component, which no longer exists, from ~4 years ago. If someone wants to go back to the original cases mentioned in the OP, and see whether or not the different syntactical scenarios are actually still reproducible with modern day rustfmt then that would be great. Any such reproducible cases should be cross referenced against other such open issues, and if there's not something that already exists then a new issue can be opened. The same applies for the different scenarios surfaced in comments over the years. Given the above, I'm going to close and lock this so that nothing gets lost. |
I have
rustfmt-preview
installed on the nightly toolchain (rustc 1.30.0-nightly (3edb355 2018-08-03)) usingrustup
.Running
cargo +nightly fmt
on the crate: https://github.com/frankmcsherry/differential-dataflow results in numerous "left behind trailing whitespace" errors. Some sample errors:The text was updated successfully, but these errors were encountered: