Closed
Description
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)