You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inconsistent handling of #[derive] on invalid targets #78331
error[E0774]: `derive` may only be applied to structs, enums and unions
--> src/main.rs:3:2
|
3 | #[derive(Copy)] impl Foo {}
| ^^^^^^^^^^^^^^^
However, applying #[derive] to a let statement just gives an "unused attribute" warning:
fnmain(){#[derive(Copy)]let _ = 1;}
warning: unused attribute
--> src/main.rs:2:5
|
2 | #[derive(Copy)] let _ = 1;
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_attributes)]` on by default
A #[derive] attribute doesn't make any more sense on a statement than it does on an item. I think we should handle these two cases in the same way.
There's been a move towards forbidding attributes on targets that don't make sense: #77015. Unless anyone objects, I think we should consistently forbid #[derive] on all invalid targets.
changed the title [-]Incosistent handling of `#[derive]` on invaid targets[/-][+]Incosistent handling of `#[derive]` on invalid targets[/+]on Oct 25, 2020
changed the title [-]Incosistent handling of `#[derive]` on invalid targets[/-][+]Inconsistent handling of `#[derive]` on invalid targets[/+]on Oct 25, 2020
Activity
Aaron1011 commentedon Oct 24, 2020
The hard error dates back to 2014 (pre-1.0): ad61ff4#diff-b6281951b118c3ea5f37605f6b8bc76cb0406fff7a59d830c16c13e9d429f1d4R354-R357
The warnings (or ast least some of them) are more recent, dating back to 2018: #50092
Aaron1011 commentedon Oct 24, 2020
I opened #78338 to do a Crater run, so we can see how much code is relying on this compiling.
[-]Incosistent handling of `#[derive]` on non-items[/-][+]Incosistent handling of `#[derive]` on invaid targets[/+][-]Incosistent handling of `#[derive]` on invaid targets[/-][+]Incosistent handling of `#[derive]` on invalid targets[/+][-]Incosistent handling of `#[derive]` on invalid targets[/-][+]Inconsistent handling of `#[derive]` on invalid targets[/+]Aaron1011 commentedon Feb 14, 2021
This was turned into a hard error by #79078