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

Illformed derive is removed #4029

Closed
jfrimmel opened this issue Jan 24, 2020 · 1 comment · Fixed by #4136
Closed

Illformed derive is removed #4029

jfrimmel opened this issue Jan 24, 2020 · 1 comment · Fixed by #4136
Labels
bug Panic, non-idempotency, invalid code, etc. good first issue Issues up for grabs, also good candidates for new rustfmt contributors

Comments

@jfrimmel
Copy link

jfrimmel commented Jan 24, 2020

When I wrote the following code:

#[derive(Debug, Clone, Default Hash)]
//                            ^-- Note the missing comma
struct S;

it got reformatted as #[derive()], i.e. the traits were removed automatically.
Since my editor did formatting on save, the code was always altered before I could try to compile it (which would have shown me the syntax error) and thus I had to stare at the code for some time until I figured it out (sometimes such obvious errors don't reach your brain). It is not directly obvious, why the derived traits are removed on Ctrl+s 😄
I expected rustfmt to not alter the code on such syntax errors.

This issue is similar to #3898.

Reproduction
cat <<EOF > test.rs
#[derive(Debug, Clone, Default Hash)]
struct S;
EOF
rustfmt test.rs 
cat test.rs
#[derive()]
struct S;

Tested versions are:

rustfmt 1.4.9-stable (33e3667 2019-10-07)
rustfmt 1.4.11-nightly (1838235 2019-12-03)
@calebcartwright
Copy link
Member

It's the same underlying problem as #3898, where parseable, but malformed, derives have the contents eaten. the base solution outlined in 3898 to keep the original span contents would solve the issue (whether the cause is double commas, missing commas, etc.

@topecongiro topecongiro added the bug Panic, non-idempotency, invalid code, etc. label Feb 10, 2020
@calebcartwright calebcartwright added the good first issue Issues up for grabs, also good candidates for new rustfmt contributors label Apr 14, 2020
ahl added a commit to ahl/rustfmt that referenced this issue Apr 22, 2020
topecongiro added a commit that referenced this issue Apr 22, 2020
calebcartwright pushed a commit to calebcartwright/rustfmt that referenced this issue Nov 29, 2020
calebcartwright pushed a commit that referenced this issue Nov 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. good first issue Issues up for grabs, also good candidates for new rustfmt contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants