Skip to content
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

Files content get deleted when formatting with #![rustfmt::skip] attribute #12458

Closed
hellow554 opened this issue Jun 3, 2022 · 5 comments
Closed
Labels
A-ide general IDE features C-bug Category: bug

Comments

@hellow554
Copy link

rust-analyzer version: rust-analyzer version: f94fa62 2022-05-30 stable

rustc version:

rustc 1.63.0-nightly (e71440575 2022-06-02)
binary: rustc
commit-hash: e71440575c930dcecac288b7c3536410d688b351
commit-date: 2022-06-02
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.4

code version:

Version: 1.67.2 (system setup)
Commit: c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
Datum: 2022-05-17T18:15:52.058Z
Electron: 17.4.1
Chromium: 98.0.4758.141
Node.js: 16.13.0
V8: 9.8.177.13-electron.0
Betriebssystem: Windows_NT x64 10.0.22621

Execute the following steps to reproduce my issue

cd $(mktemp -d)
cargo init . --name abc
echo -e '#![rustfmt::skip]\n\nfn main() {}' > src/main.rs
code .

wait until rust-analyzer is ready, open src/main.rs and then press alt + shift + f for formatting the file.

The whole content of the file gets truncated. I can't reproduce the issue with rustfmt itself, so rustfmt src/main.rs does nothing (as expected).

@flodiebold flodiebold added C-bug Category: bug A-ide general IDE features labels Jun 3, 2022
@jhgg
Copy link
Contributor

jhgg commented Jun 4, 2022

This is indeed reproducible with rustfmt, with cat src/main.rs | rustfmt

Here, with #![rustfmt::skip] present, rustfmt outputs nothing to stdout. This is how rust-analyzer invokes rustfmt, it writes to stdin, and then expects the formatted output to come out from stdout.

We could work around this for the time being by checking if rust-fmt ended up returning nothing we just use the original input. However that is quite hacky.

Rustfmt does not return a non-zero exit code under this situation either :\

@jhgg
Copy link
Contributor

jhgg commented Jun 4, 2022

I've bisected this to a regression in rustfmt introduced in: rust-lang/rustfmt#5094 - I've opened an issue in rustfmt on this: rust-lang/rustfmt#5368

@jhgg
Copy link
Contributor

jhgg commented Jun 4, 2022

The fix to rustfmt has landed. So we can probably close this out now - it should be fixed by upgrading to a new nightly tool chain at some point in the future.

@Veykril Veykril closed this as completed Jun 4, 2022
@hellow554
Copy link
Author

Thanks for your support! That was quick.

@calebcartwright
Copy link
Member

Believe the fix is out in nightly-2021-06-15, plus or minus a day or two

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

5 participants