Description
Description
There are quite a few attributes that have been accidentally allowed in positions that make no sense. For example:
#[windows_subsystem = "windows"]
pub struct Bar {
#[no_link]
pub field: u32,
}
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
--> src/lib.rs:1:1
|
1 | #[windows_subsystem = "windows"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_attributes)]` on by default
warning: `#[no_link]` is ignored on struct fields, match arms and macro defs
--> src/lib.rs:3:5
|
3 | #[no_link]
| ^^^^^^^^^^
In check_attr.rs
there are various comments along the lines of "we accidentally allowed this". Some attributes are even not checked at all. In almost all cases, the attribute does nothing and is simply ignored.
Proposal
Once the attribute rework is completed we can consistently and reliably handle these cases. I propose that once that is done, we start on a path to turning these into errors.
I'd like to hear the lang team's thoughts on this. In particular,
- For the cases where the attribute does nothing and there is no behavioral change to consider, that we turn them into a hard error over a future edition.
- That we start emitting "this will be an error in a future release" diagnostics for these cases.
#142836 is adjacent and related to this issue, but different; that one asks for a decision about behavior in ambiguous situations, this one is about getting rid of obvious nonsense.
@rustbot labels +I-lang-nominated