Skip to content

Confusing warning when using link_section on extern static #136220

Description

@RalfJung

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions