Skip to content

"attr is not an unsafe attribute" diagnostic is emitted even if the attribute doesn't exist #148453

@Fulgen301

Description

@Fulgen301

Code

#[unsafe(nonexistent)]
fn foo() {}

Current output

error: `nonexistent` is not an unsafe attribute
 --> src/lib.rs:1:3
  |
1 | #[unsafe(nonexistent)]
  |   ^^^^^^ this is not an unsafe attribute
  |
  = note: extraneous unsafe is not allowed in attributes

error: cannot find attribute `nonexistent` in this scope
 --> src/lib.rs:1:10
  |
1 | #[unsafe(nonexistent)]
  |          ^^^^^^^^^^^

Desired output

error: cannot find attribute `nonexistent` in this scope
 --> src/lib.rs:1:10
  |
1 | #[unsafe(nonexistent)]
  |          ^^^^^^^^^^^

Rationale and extra context

While it is true that an attribute that doesn't exist isn't unsafe, the diagnostic provides not much to no additional value, and is emitted first, pushing the real error down. If both diagnostics should be kept, the one about the attribute not existing should probably be emitted first.

Other cases

Rust Version

rustc 1.91.0, on the Playground

Anything else?

No response

Metadata

Metadata

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.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