The following code:
fn main() {
struct Foo {}
#[derive(Copy)] impl Foo {}
}
produces the following error
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:
fn main() {
#[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.
The following code:
produces the following error
However, applying
#[derive]to aletstatement just gives an "unused attribute" warning: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.