Confusing warning when using `link_section` on `extern static`
Open
Nobody has claimed this yet.
A-diagnostics
E-needs-test
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
unsafe extern {
#[unsafe(link_section = ".buffer")]
pub static mut a: [u8; 1024];
}
Current output
warning: attribute should be applied to a function or static
--> <source>:10:5
|
10 | #[unsafe(link_section = ".buffer")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11 | pub static mut a: [u8; 1024];
| ----------------------------- not a function or static
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: `#[warn(unused_attributes)]` on by default
warning: 1 warning emitted
Desired output
Not sure if the attribute should be allowed on extern statics... but if the answer is no, the warning should still be reworded to avoid saying that an extern static is "not a static".
Rationale and extra context
No response
Other cases
Rust Version
Rust 1.84
Anything else?
Example due by @moridinga
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Rust 1.84 example with an unsafe extern static and capture the current warning. Trace the compiler diagnostic for link_section and check how extern statics are classified. Done means determining whether the attribute is allowed and ensuring any rejection or warning describes the declaration accurately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100