Skip to content

Duplicate warning on some attributes with wrong targets #147417

@JonathanBrouwer

Description

@JonathanBrouwer

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

Metadata

Metadata

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions