Duplicate warning on some attributes with wrong targets
Open
@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
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.
Assessment
This issue has not been assessed yet.