rust-lang / rust-lang/rust

Duplicate warning on some attributes with wrong targets

Open
#147,417 6 comments 0 reactions 1 assignee View on GitHub

@JonathanBrouwer is already working on this.

Since Oct 6, 2025.

A-attributes A-diagnostics C-bug P-medium regression-from-stable-to-stable T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

The following three cases create a hard error AND a warning:

fn main() {
    #[no_mangle] || {};
}
error: `#[no_mangle]` cannot be used on a closure as it has no name
 --> src/main.rs:2:5
  |
2 |     #[no_mangle] || {};
  |     ^^^^^^^^^^^^

warning: `#[no_mangle]` attribute cannot be used on closures
 --> src/main.rs:2:5
  |
2 |     #[no_mangle] || {};
  |     ^^^^^^^^^^^^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = help: `#[no_mangle]` can be applied to methods, functions, and statics
  = note: `#[warn(unused_attributes)]` (part of `#[warn(unused)]`) on by default
#[inline]
macro_rules! test {
    () => {}
}
error[E0518]: attribute should be applied to function or closure
 --> src/main.rs:5:1
  |
5 | #[inline]
  | ^^^^^^^^^ not a function or closure

warning: `#[inline]` attribute cannot be used on macro defs
 --> src/main.rs:5:1
  |
5 | #[inline]
  | ^^^^^^^^^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = help: `#[inline]` can only be applied to functions
  = note: `#[warn(unused_attributes)]` (part of `#[warn(unused)]`) on by default
#[no_mangle] pub const RAH: usize = 5;
warning: `#[no_mangle]` attribute cannot be used on constants
  --> src/main.rs:10:1
   |
10 | #[no_mangle] pub const RAH: usize = 5;
   | ^^^^^^^^^^^^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = help: `#[no_mangle]` can be applied to functions and statics
   = note: `#[warn(unused_attributes)]` (part of `#[warn(unused)]`) on by default

error: const items should never be `#[no_mangle]`
  --> src/main.rs:10:14
   |
10 | #[no_mangle] pub const RAH: usize = 5;
   |              ---------^^^^^^^^^^^^^^^^
   |              |
   |              help: try a static value: `pub static`
   |
   = note: `#[deny(no_mangle_const_items)]` on by default

@rustbot claim

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.