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

Formatting file empties file #11285

Closed
Ten0 opened this issue Jan 14, 2022 · 3 comments
Closed

Formatting file empties file #11285

Ten0 opened this issue Jan 14, 2022 · 3 comments

Comments

@Ten0
Copy link

Ten0 commented Jan 14, 2022

rust-analyzer version: 0add6e9 2021-12-20 stable
rustc version: rustc 1.58.0 (02072b482 2022-01-11)

Formatting files that have @generated instead empties the whole file.
This issue will hit more users as we had to use rustfmt +nightly before to encounter it, while with the 1.58 release all users will be affected.

This only happens if format_generated_files is false in rustfmt.toml (newly released in 1.58).

@bjorn3
Copy link
Member

bjorn3 commented Jan 14, 2022

This is a rustfmt bug. It doesn't return any code if the input to format contains @generated.

$ echo "//@notgenerated\nfn   foo() {}" | rustfmt
//@notgenerated
fn foo() {}
$ echo "//@generated\nfn   foo() {}" | rustfmt

Instead it should emit the original code.

@bjorn3
Copy link
Member

bjorn3 commented Jan 14, 2022

Opened rust-lang/rustfmt#5172.

@bjorn3
Copy link
Member

bjorn3 commented Jan 19, 2022

Rust 1.58.1 will contain a fix (rust-lang/rust#93071). It will probably be released tomorrow.

@Veykril Veykril closed this as completed Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants