-
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
error[internal]: left behind trailing whitespace on long lines in raw string #3968
Comments
hi @lucidBrot - this error is not reproducible in the latest versions of rustfmt, so it was resolved some time back |
Hi @calebcartwright Eric@Sharkoon /cygdrive/n/Temp/rustbuga
$ cargo +nightly fmt
error[internal]: left behind trailing whitespace
--> \\?\N:\Temp\rustbuga\src\main.rs:1:1:27
|
1 | const CONFIG_STRING: &str =
| ^
|
warning: rustfmt has failed to format. See previous 1 errors.
Eric@Sharkoon /cygdrive/n/Temp/rustbuga
$ cargo +nightly --version
cargo 1.41.0-nightly (750cb1482 2019-11-23)
and on both of my devices. It also does not seem to be a cygwin-related bug, as it also happens in windows cmd |
Easiest way would be to use
which will update you to rustfmt 1.4.8 or newer IIRC
Yeah these |
I have run
|
Thanks! Seems like this was one of the more recent fixes then since it's working for me on 1.4.11. What about |
Same thing:
|
👀 yikes. I'll take a closer look into it later today. I'm using the latest version of rustfmt off the master branch in my env where I cannot reproduce, so either there's something else going on, or perhaps a very recent fix has resolved this one already 🤞 We're primarily focused on rustfmt 2.x right now so there's quite a few changes on the master branch that weren't in rustfmt 1.4.11 (which was released relatively recently with an urgent bug fix) so I'm hopeful that's what's happening |
Thanks a lot! It's not urgent for me personally, since I can fix my use case simply by removing the trailing space manually. But I'm happy I did not end up being the stupid dude who did not update before reporting a bug (although I did not update at first 😅). |
This gets even stranger 🤔 I still can't reproduce this on Ubuntu but I can on my Windows machine |
I'll play around with CR/LF line endings if I get to it this evening. Edit: |
I cannot reproduce this as of |
I updated again using rustup and am now on
To be clear, I am currently using the last "bad" of my examples. Which is this: const CONFIG_STRING: &str =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
fn main() {
println!("Hello, world: {}", CONFIG_STRING);
} |
@lucidBrot - one admittedly confusing thing here is that the released 1.4.11 version of rustfmt that you are getting from rustup is a hotfix version of rustfmt that's actually older than the current rustfmt on master branch (master is targeting a planned 2.0 release of rustfmt, but the After re-checking that I had the latest rustfmt version (on master) on my Windows machine, I can't reproduce this one either (Seems I was using a slightly older rustfmt version on Windows before when I was able to reproduce). As such I believe this bug has already been fixed in the most recent version of rustfmt on master, but that fix hasn't been released yet. If you wanted to test the latest version of rustfmt on your machine against this snippet, you could try installing rustfmt directly from source. To do so, clone this repo and then run the below command in the root directory: cargo +nightly install --path . --force --locked |
Thanks for the clear instructions! What surprised me a bit is that Eric@Sharkoon /cygdrive/n/Temp/rustbuga
$ cargo fmt --version
rustfmt 1.4.10-nightly (1e04b5ee 2019-12-20)
Eric@Sharkoon /cygdrive/n/Temp/rustbuga
$ cargo +nightly fmt --version
rustfmt 1.4.10-nightly (1e04b5ee 2019-12-20) If you happen to know whether that is intentional, let me know. Otherwise I won't bother with it. Thank you two for your time and help! |
Assuming you'd prefer to switch back to the bundled/released version of rustfmt, the below commands should get you reset cargo +nightly uninstall
rustup update |
System
Reproduction
rustfmt fails on this code sample.
The error it prints is this:
This code sample, which has one
a
less, is successfully formatted:The successfully formatted version looks like this:
Another version of this snippet that can successfully be formatted is the following. It has the same number of
a
s as the problematic example, but no trailing space after the equal sign on line 1:Possibly Related
I don't know enough to say for sure. That's why I created a new issue. But these may or may not be related:
#2896 (open)
#3295 (nightly) (closed)
#2896 (open) (collection thread)
More Examples
Good (Can be formatted):
Bad (Can not successfully be formatted):
Good:
Bad:
Has no whitespace after the equal sign, but a long raw string
Good:
Just like the sample right above this one, except it has one
a
less:Bad:
no longer a raw string
Splitting into multiple lines makes the bug disappear.
Good:
Conclusion
It seems like this bug has to do with all of these in some way:
a
s vs 89a
s (I think the counts are correct?) - or rather, the length of the line as a whole.When there is no whitespace after the equal sign, the number of
a
s is irrelevant and formatting works.When there are few enough
a
s, the formatting works even with the whitespace.The text was updated successfully, but these errors were encountered: